This commit is contained in:
Timo Hocker 2019-09-19 12:28:14 +02:00
parent 0405443391
commit 4960433c0a
2 changed files with 20 additions and 14 deletions

View File

@ -1,6 +1,7 @@
const path = require('path');
const fs = require('fs');
const express = require('express');
const bodyParser = require('body-parser');
const config = JSON.parse(fs.readFileSync('config.json', 'utf-8'));
@ -14,25 +15,29 @@ const pg = require('postgresupdater')(
const app = express();
app.use(express.json());
app.use(bodyParser.text({type: '*/*'}));
app.post('/', (req, res, next) => {
console.log('post');
if (req.query.json) {
// json mod requests
} else {
console.log(req.body);
pg.query(
`INSERT INTO "Log" ("App", "Type", "Client", "Message", "Misc", "Stack") Values($1, $2, $3, $4, $5, $6)`,
[
req.body.app,
req.body.type,
req.body.client,
req.body.message,
req.body.misc,
req.body.stack
]
);
try {
const json = JSON.parse(req.body);
pg.query(
`INSERT INTO "Log" ("App", "Type", "Client", "Message", "Misc", "Stack") Values($1, $2, $3, $4, $5, $6)`,
[
json.app,
json.type,
json.client,
json.message,
json.misc,
json.stack
]
);
} catch {
console.log('invalid json', req.body);
}
}
res.status(201).end();
next();

View File

@ -13,6 +13,7 @@
"author": "Timo Hocker",
"license": "GPL-3.0-or-later",
"dependencies": {
"body-parser": "^1.19.0",
"express": "^4.17.1",
"postgresupdater": "^1.0.0"
}