fixes
This commit is contained in:
parent
0405443391
commit
4960433c0a
33
index.js
33
index.js
@ -1,6 +1,7 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
|
const bodyParser = require('body-parser');
|
||||||
|
|
||||||
const config = JSON.parse(fs.readFileSync('config.json', 'utf-8'));
|
const config = JSON.parse(fs.readFileSync('config.json', 'utf-8'));
|
||||||
|
|
||||||
@ -14,25 +15,29 @@ const pg = require('postgresupdater')(
|
|||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
app.use(express.json());
|
app.use(bodyParser.text({type: '*/*'}));
|
||||||
|
|
||||||
app.post('/', (req, res, next) => {
|
app.post('/', (req, res, next) => {
|
||||||
console.log('post');
|
console.log('post');
|
||||||
if (req.query.json) {
|
if (req.query.json) {
|
||||||
// json mod requests
|
// json mod requests
|
||||||
} else {
|
} else {
|
||||||
console.log(req.body);
|
try {
|
||||||
pg.query(
|
const json = JSON.parse(req.body);
|
||||||
`INSERT INTO "Log" ("App", "Type", "Client", "Message", "Misc", "Stack") Values($1, $2, $3, $4, $5, $6)`,
|
pg.query(
|
||||||
[
|
`INSERT INTO "Log" ("App", "Type", "Client", "Message", "Misc", "Stack") Values($1, $2, $3, $4, $5, $6)`,
|
||||||
req.body.app,
|
[
|
||||||
req.body.type,
|
json.app,
|
||||||
req.body.client,
|
json.type,
|
||||||
req.body.message,
|
json.client,
|
||||||
req.body.misc,
|
json.message,
|
||||||
req.body.stack
|
json.misc,
|
||||||
]
|
json.stack
|
||||||
);
|
]
|
||||||
|
);
|
||||||
|
} catch {
|
||||||
|
console.log('invalid json', req.body);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
res.status(201).end();
|
res.status(201).end();
|
||||||
next();
|
next();
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
"author": "Timo Hocker",
|
"author": "Timo Hocker",
|
||||||
"license": "GPL-3.0-or-later",
|
"license": "GPL-3.0-or-later",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"body-parser": "^1.19.0",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"postgresupdater": "^1.0.0"
|
"postgresupdater": "^1.0.0"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user