Compare commits
11 Commits
078ad18862
...
master
Author | SHA1 | Date | |
---|---|---|---|
627cfa8592 | |||
653cc41ff2 | |||
ad17778f38 | |||
687735e29e | |||
de3ec4572d | |||
a8223d110b | |||
207c7c3ba9 | |||
f493dfaed0 | |||
2db228bdb1 | |||
850091188f | |||
b6bccfb07f |
11
README.md
11
README.md
@ -54,18 +54,17 @@ window.onerror = async function(msg, source, lineno, colno, error) {
|
||||
let data;
|
||||
if (error) {
|
||||
data = {
|
||||
app: 'app1',
|
||||
type: 'error',
|
||||
client: appClientId,
|
||||
message: msg,
|
||||
stack: error.stack,
|
||||
misc: `v: ${appVersion} src: ${source} ln: ${lineno} col: ${colno}`
|
||||
};
|
||||
} else {
|
||||
data = { message: msg };
|
||||
data = { app: 'app1', type: 'error', client: appClientId, message: msg };
|
||||
}
|
||||
/*
|
||||
* the first 4 characters of the client will be displayed as app
|
||||
* the remaining characters (up to 64) will be displayed as client
|
||||
*/
|
||||
fetch('http://localhost:8080?client=app1' + appClientId, {
|
||||
fetch('http://localhost:8080', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data),
|
||||
mode: 'no-cors'
|
||||
|
@ -6,5 +6,11 @@
|
||||
"password": "12345",
|
||||
"database": "appreports"
|
||||
},
|
||||
"port": "8080"
|
||||
"port": "8080",
|
||||
"restrictClients": false,
|
||||
"allowedClients": [
|
||||
"127.0.0.1",
|
||||
"::1"
|
||||
],
|
||||
"clearLogAfterDays": -1
|
||||
}
|
||||
|
50
index.js
50
index.js
@ -1,4 +1,3 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const express = require('express');
|
||||
const bodyParser = require('body-parser');
|
||||
@ -15,22 +14,25 @@ const pg = require('postgresupdater')(
|
||||
|
||||
const app = express();
|
||||
|
||||
const tryParseJSON = function(text) {
|
||||
try {
|
||||
return JSON.parse(text);
|
||||
} catch {
|
||||
console.log('invalid json');
|
||||
}
|
||||
};
|
||||
|
||||
app.use(bodyParser.text({ type: '*/*' }));
|
||||
|
||||
app.post('/', (req, res, next) => {
|
||||
console.log('post');
|
||||
if (req.query.json) {
|
||||
// json mod requests
|
||||
const json = tryParseJSON(req.body);
|
||||
if (typeof req.query.json != 'undefined') {
|
||||
//json mod requests
|
||||
} 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);
|
||||
}
|
||||
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]
|
||||
);
|
||||
}
|
||||
res.status(201).end();
|
||||
next();
|
||||
@ -38,17 +40,35 @@ app.post('/', (req, res, next) => {
|
||||
|
||||
app.get('/', async (req, res, next) => {
|
||||
if (typeof req.query.json != 'undefined') {
|
||||
if (
|
||||
config.restrictClients &&
|
||||
!config.allowedClients.includes(req.connection.remoteAddress)
|
||||
) {
|
||||
console.log('blocked request from ' + req.connection.remoteAddress);
|
||||
res.status(403).end();
|
||||
return;
|
||||
}
|
||||
|
||||
const data = await pg.query(
|
||||
`SELECT "Timestamp", "Type", "App", "Client", "Message", "Misc", "Stack" FROM "LogView"`
|
||||
`SELECT "ID", "Timestamp", "Type", "App", "Client", "Message", "Misc", "Stack" FROM "Log" ORDER BY "Timestamp" ASC`
|
||||
);
|
||||
const rows = [];
|
||||
const headings = data.rows.length > 0 ? Object.keys(data.rows[0]) : [];
|
||||
const hiddenData = [0];
|
||||
for (let row of data.rows) {
|
||||
rows.push(Object.values(row));
|
||||
}
|
||||
res
|
||||
.status(200)
|
||||
.type('application/json')
|
||||
.end(JSON.stringify(rows));
|
||||
.end(
|
||||
JSON.stringify({ headings: headings, data: rows, hidden: hiddenData })
|
||||
);
|
||||
try {
|
||||
const clearLogInterval = Number.parseInt(config.clearLogAfterDays);
|
||||
if (clearLogInterval > 0)
|
||||
await pg.query(`DELETE FROM "Log" WHERE "Timestamp" < now() - interval '${clearLogInterval} days'`);
|
||||
} catch (e) {}
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
|
26
package-lock.json
generated
26
package-lock.json
generated
@ -264,14 +264,15 @@
|
||||
"integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w="
|
||||
},
|
||||
"pg": {
|
||||
"version": "7.12.1",
|
||||
"resolved": "https://registry.npmjs.org/pg/-/pg-7.12.1.tgz",
|
||||
"integrity": "sha512-l1UuyfEvoswYfcUe6k+JaxiN+5vkOgYcVSbSuw3FvdLqDbaoa2RJo1zfJKfPsSYPFVERd4GHvX3s2PjG1asSDA==",
|
||||
"version": "7.17.1",
|
||||
"resolved": "https://registry.npmjs.org/pg/-/pg-7.17.1.tgz",
|
||||
"integrity": "sha512-SYWEip6eADsgDQIZk0bmB2JDOrC8Xu6z10KlhlXl03NSomwVmHB6ZTVyDCwOfT6bXHI8QndJdk5XxSSRXikaSA==",
|
||||
"requires": {
|
||||
"buffer-writer": "2.0.0",
|
||||
"packet-reader": "1.0.0",
|
||||
"pg-connection-string": "0.1.3",
|
||||
"pg-pool": "^2.0.4",
|
||||
"pg-packet-stream": "^1.1.0",
|
||||
"pg-pool": "^2.0.9",
|
||||
"pg-types": "^2.1.0",
|
||||
"pgpass": "1.x",
|
||||
"semver": "4.3.2"
|
||||
@ -287,10 +288,15 @@
|
||||
"resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz",
|
||||
"integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw=="
|
||||
},
|
||||
"pg-packet-stream": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/pg-packet-stream/-/pg-packet-stream-1.1.0.tgz",
|
||||
"integrity": "sha512-kRBH0tDIW/8lfnnOyTwKD23ygJ/kexQVXZs7gEyBljw4FYqimZFxnMMx50ndZ8In77QgfGuItS5LLclC2TtjYg=="
|
||||
},
|
||||
"pg-pool": {
|
||||
"version": "2.0.7",
|
||||
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-2.0.7.tgz",
|
||||
"integrity": "sha512-UiJyO5B9zZpu32GSlP0tXy8J2NsJ9EFGFfz5v6PSbdz/1hBLX1rNiiy5+mAm5iJJYwfCv4A0EBcQLGWwjbpzZw=="
|
||||
"version": "2.0.9",
|
||||
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-2.0.9.tgz",
|
||||
"integrity": "sha512-gNiuIEKNCT3OnudQM2kvgSnXsLkSpd6mS/fRnqs6ANtrke6j8OY5l9mnAryf1kgwJMWLg0C1N1cYTZG1xmEYHQ=="
|
||||
},
|
||||
"pg-types": {
|
||||
"version": "2.2.0",
|
||||
@ -336,9 +342,9 @@
|
||||
}
|
||||
},
|
||||
"postgresupdater": {
|
||||
"version": "1.0.13",
|
||||
"resolved": "https://registry.npmjs.org/postgresupdater/-/postgresupdater-1.0.13.tgz",
|
||||
"integrity": "sha512-pKPEZCR42lLjx8uYmf+Bqccdmx5tUa1CHGsNK91AEpEy8lM9CLuXkitLHFaiSG37bUweqSdd4C5a//mGTS/9Vw==",
|
||||
"version": "1.0.16",
|
||||
"resolved": "https://registry.npmjs.org/postgresupdater/-/postgresupdater-1.0.16.tgz",
|
||||
"integrity": "sha512-6pe6ozTKwSqevDcXC/WIUvb0qBMUlCWtwKb8EOg1c+qf12Hyh+5U/t5Mq79QI8Pa3Z7d86nStGhnVpSevH2HHg==",
|
||||
"requires": {
|
||||
"pg": "^7.12.1"
|
||||
}
|
||||
|
@ -15,6 +15,6 @@
|
||||
"dependencies": {
|
||||
"body-parser": "^1.19.0",
|
||||
"express": "^4.17.1",
|
||||
"postgresupdater": "^1.0.13"
|
||||
"postgresupdater": "^1.0.16"
|
||||
}
|
||||
}
|
||||
|
2
updates/2.sql
Normal file
2
updates/2.sql
Normal file
@ -0,0 +1,2 @@
|
||||
-- drop view
|
||||
DROP VIEW public."LogView";
|
@ -1,9 +1,19 @@
|
||||
<template>
|
||||
<div id="app">
|
||||
<div>
|
||||
<div v-if="json.headings && json.data">
|
||||
<p>successfully loaded {{json.data.length}} entries</p>
|
||||
<table>
|
||||
<tr v-for="(row,rowKey) in json" :key="rowKey">
|
||||
<td v-for="(value,key) in row" :key="key">{{value}}</td>
|
||||
<tr>
|
||||
<th
|
||||
v-for="(value, key) in json.headings.filter((val,ind)=>!json.hidden.includes(ind))"
|
||||
:key="key"
|
||||
>{{value}}</th>
|
||||
</tr>
|
||||
<tr v-for="(row,rowKey) in json.data" :key=rowKey>
|
||||
<td
|
||||
v-for="(value,key) in row.filter((val,ind)=>!json.hidden.includes(ind))"
|
||||
:key="key"
|
||||
>{{value}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
@ -22,7 +32,7 @@ export default {
|
||||
name: "App",
|
||||
data() {
|
||||
return {
|
||||
json: []
|
||||
json: {}
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
@ -30,11 +40,6 @@ export default {
|
||||
fetch("?json")
|
||||
.then(res => res.json())
|
||||
.then(json => (self.json = json));
|
||||
},
|
||||
watch: {
|
||||
json() {
|
||||
console.log(this.json);
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
@ -47,6 +52,10 @@ td {
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
th {
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
Reference in New Issue
Block a user