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;
|
let data;
|
||||||
if (error) {
|
if (error) {
|
||||||
data = {
|
data = {
|
||||||
|
app: 'app1',
|
||||||
|
type: 'error',
|
||||||
|
client: appClientId,
|
||||||
message: msg,
|
message: msg,
|
||||||
stack: error.stack,
|
stack: error.stack,
|
||||||
misc: `v: ${appVersion} src: ${source} ln: ${lineno} col: ${colno}`
|
misc: `v: ${appVersion} src: ${source} ln: ${lineno} col: ${colno}`
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
data = { message: msg };
|
data = { app: 'app1', type: 'error', client: appClientId, message: msg };
|
||||||
}
|
}
|
||||||
/*
|
fetch('http://localhost:8080', {
|
||||||
* 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, {
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify(data),
|
body: JSON.stringify(data),
|
||||||
mode: 'no-cors'
|
mode: 'no-cors'
|
||||||
|
@ -6,5 +6,11 @@
|
|||||||
"password": "12345",
|
"password": "12345",
|
||||||
"database": "appreports"
|
"database": "appreports"
|
||||||
},
|
},
|
||||||
"port": "8080"
|
"port": "8080",
|
||||||
|
"restrictClients": false,
|
||||||
|
"allowedClients": [
|
||||||
|
"127.0.0.1",
|
||||||
|
"::1"
|
||||||
|
],
|
||||||
|
"clearLogAfterDays": -1
|
||||||
}
|
}
|
||||||
|
40
index.js
40
index.js
@ -1,4 +1,3 @@
|
|||||||
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 bodyParser = require('body-parser');
|
||||||
@ -15,22 +14,25 @@ const pg = require('postgresupdater')(
|
|||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
|
const tryParseJSON = function(text) {
|
||||||
|
try {
|
||||||
|
return JSON.parse(text);
|
||||||
|
} catch {
|
||||||
|
console.log('invalid json');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
app.use(bodyParser.text({ type: '*/*' }));
|
app.use(bodyParser.text({ type: '*/*' }));
|
||||||
|
|
||||||
app.post('/', (req, res, next) => {
|
app.post('/', (req, res, next) => {
|
||||||
console.log('post');
|
const json = tryParseJSON(req.body);
|
||||||
if (req.query.json) {
|
if (typeof req.query.json != 'undefined') {
|
||||||
//json mod requests
|
//json mod requests
|
||||||
} else {
|
} else {
|
||||||
try {
|
|
||||||
const json = JSON.parse(req.body);
|
|
||||||
pg.query(
|
pg.query(
|
||||||
`INSERT INTO "Log" ("App", "Type", "Client", "Message", "Misc", "Stack") Values($1, $2, $3, $4, $5, $6)`,
|
`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]
|
[json.app, json.type, json.client, json.message, json.misc, json.stack]
|
||||||
);
|
);
|
||||||
} catch {
|
|
||||||
console.log('invalid json', req.body);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
res.status(201).end();
|
res.status(201).end();
|
||||||
next();
|
next();
|
||||||
@ -38,17 +40,35 @@ app.post('/', (req, res, next) => {
|
|||||||
|
|
||||||
app.get('/', async (req, res, next) => {
|
app.get('/', async (req, res, next) => {
|
||||||
if (typeof req.query.json != 'undefined') {
|
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(
|
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 rows = [];
|
||||||
|
const headings = data.rows.length > 0 ? Object.keys(data.rows[0]) : [];
|
||||||
|
const hiddenData = [0];
|
||||||
for (let row of data.rows) {
|
for (let row of data.rows) {
|
||||||
rows.push(Object.values(row));
|
rows.push(Object.values(row));
|
||||||
}
|
}
|
||||||
res
|
res
|
||||||
.status(200)
|
.status(200)
|
||||||
.type('application/json')
|
.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 {
|
} else {
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
26
package-lock.json
generated
26
package-lock.json
generated
@ -264,14 +264,15 @@
|
|||||||
"integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w="
|
"integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w="
|
||||||
},
|
},
|
||||||
"pg": {
|
"pg": {
|
||||||
"version": "7.12.1",
|
"version": "7.17.1",
|
||||||
"resolved": "https://registry.npmjs.org/pg/-/pg-7.12.1.tgz",
|
"resolved": "https://registry.npmjs.org/pg/-/pg-7.17.1.tgz",
|
||||||
"integrity": "sha512-l1UuyfEvoswYfcUe6k+JaxiN+5vkOgYcVSbSuw3FvdLqDbaoa2RJo1zfJKfPsSYPFVERd4GHvX3s2PjG1asSDA==",
|
"integrity": "sha512-SYWEip6eADsgDQIZk0bmB2JDOrC8Xu6z10KlhlXl03NSomwVmHB6ZTVyDCwOfT6bXHI8QndJdk5XxSSRXikaSA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"buffer-writer": "2.0.0",
|
"buffer-writer": "2.0.0",
|
||||||
"packet-reader": "1.0.0",
|
"packet-reader": "1.0.0",
|
||||||
"pg-connection-string": "0.1.3",
|
"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",
|
"pg-types": "^2.1.0",
|
||||||
"pgpass": "1.x",
|
"pgpass": "1.x",
|
||||||
"semver": "4.3.2"
|
"semver": "4.3.2"
|
||||||
@ -287,10 +288,15 @@
|
|||||||
"resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz",
|
||||||
"integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw=="
|
"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": {
|
"pg-pool": {
|
||||||
"version": "2.0.7",
|
"version": "2.0.9",
|
||||||
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-2.0.7.tgz",
|
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-2.0.9.tgz",
|
||||||
"integrity": "sha512-UiJyO5B9zZpu32GSlP0tXy8J2NsJ9EFGFfz5v6PSbdz/1hBLX1rNiiy5+mAm5iJJYwfCv4A0EBcQLGWwjbpzZw=="
|
"integrity": "sha512-gNiuIEKNCT3OnudQM2kvgSnXsLkSpd6mS/fRnqs6ANtrke6j8OY5l9mnAryf1kgwJMWLg0C1N1cYTZG1xmEYHQ=="
|
||||||
},
|
},
|
||||||
"pg-types": {
|
"pg-types": {
|
||||||
"version": "2.2.0",
|
"version": "2.2.0",
|
||||||
@ -336,9 +342,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"postgresupdater": {
|
"postgresupdater": {
|
||||||
"version": "1.0.13",
|
"version": "1.0.16",
|
||||||
"resolved": "https://registry.npmjs.org/postgresupdater/-/postgresupdater-1.0.13.tgz",
|
"resolved": "https://registry.npmjs.org/postgresupdater/-/postgresupdater-1.0.16.tgz",
|
||||||
"integrity": "sha512-pKPEZCR42lLjx8uYmf+Bqccdmx5tUa1CHGsNK91AEpEy8lM9CLuXkitLHFaiSG37bUweqSdd4C5a//mGTS/9Vw==",
|
"integrity": "sha512-6pe6ozTKwSqevDcXC/WIUvb0qBMUlCWtwKb8EOg1c+qf12Hyh+5U/t5Mq79QI8Pa3Z7d86nStGhnVpSevH2HHg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"pg": "^7.12.1"
|
"pg": "^7.12.1"
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,6 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"body-parser": "^1.19.0",
|
"body-parser": "^1.19.0",
|
||||||
"express": "^4.17.1",
|
"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>
|
<template>
|
||||||
<div id="app">
|
<div id="app">
|
||||||
<div>
|
<div v-if="json.headings && json.data">
|
||||||
|
<p>successfully loaded {{json.data.length}} entries</p>
|
||||||
<table>
|
<table>
|
||||||
<tr v-for="(row,rowKey) in json" :key="rowKey">
|
<tr>
|
||||||
<td v-for="(value,key) in row" :key="key">{{value}}</td>
|
<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>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
@ -22,7 +32,7 @@ export default {
|
|||||||
name: "App",
|
name: "App",
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
json: []
|
json: {}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
@ -30,11 +40,6 @@ export default {
|
|||||||
fetch("?json")
|
fetch("?json")
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(json => (self.json = json));
|
.then(json => (self.json = json));
|
||||||
},
|
|
||||||
watch: {
|
|
||||||
json() {
|
|
||||||
console.log(this.json);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
@ -47,6 +52,10 @@ td {
|
|||||||
padding: 5px;
|
padding: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
th {
|
||||||
|
padding: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
table {
|
table {
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user