diff --git a/index.js b/index.js index f3f48dd..31d1236 100644 --- a/index.js +++ b/index.js @@ -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 - ] - ); + } else { + 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(); diff --git a/package.json b/package.json index 2697fc0..8f36c34 100644 --- a/package.json +++ b/package.json @@ -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" }