This commit is contained in:
Timo Hocker 2019-09-03 12:24:50 +02:00
parent 41a6bf7048
commit 0405443391
5 changed files with 10 additions and 95 deletions

View File

@ -1,7 +1,5 @@
cd web
call npm ci
call npm run build
mkdir ../html
robocopy ./dist ../html /MIR
cd ..
npm ci

View File

@ -1,6 +1,4 @@
cd web
npm ci
npm run build
cp -R ./dist ../html
cd ..
npm ci

View File

@ -1,5 +1,3 @@
// const http = require('http');
// const url = require('url');
const path = require('path');
const fs = require('fs');
const express = require('express');
@ -17,7 +15,6 @@ const pg = require('postgresupdater')(
const app = express();
app.use(express.json());
app.use(express.static(path.join(__dirname, 'html')));
app.post('/', (req, res, next) => {
console.log('post');
@ -41,9 +38,8 @@ app.post('/', (req, res, next) => {
next();
});
app.get('/', async (req, res, next) => {
console.log('get');
if (req.query.json) {
app.get('/*', async (req, res, next) => {
if (typeof req.query.json != 'undefined') {
const data = await pg.query(
`SELECT "Timestamp", "Type", "App", "Client", "Message", "Misc", "Stack" FROM "LogView"`
);
@ -55,58 +51,11 @@ app.get('/', async (req, res, next) => {
.status(200)
.type('application/json')
.end(JSON.stringify(rows));
return;
next();
} else {
express.static(path.join(__dirname, 'html'))(req, res, next);
}
next();
});
app.listen(config.port);
// const server = http.createServer(async (req, res) => {
// await pg.waitForInit();
// const queryUrl = url.parse(req.url, true);
// let body;
// req.on('data', data => {
// body += data;
// });
// req.on('end', async () => {
// if (!body && !queryUrl.search) {
// fs.readFile('view.html', (err, file) => {
// res.writeHead(200, { 'content-type': 'text/html' });
// res.end(file);
// });
// return;
// } else if (queryUrl.search == '?json') {
// const data = await pg.query(
// `SELECT "Timestamp", "Type", "App", "Client", "Message", "Misc", "Stack" FROM "LogView"`
// );
// const rows = [];
// for (let row of data.rows) {
// rows.push(Object.values(row));
// }
// res.writeHead(200, { 'content-type': 'application/json' });
// res.end(JSON.stringify(rows));
// return;
// }
// try {
// body = JSON.parse(/(?:undefined)*(.*)/.exec(body)[1]);
// console.log(body.app, body.client, body.message, body.misc, body.stack);
// pg.query(
// `INSERT INTO "Log" ("App", "Type", "Client", "Message", "Misc", "Stack") Values($1, $2, $3, $4, $5, $6)`,
// [body.app, body.type, body.client, body.message, body.misc, body.stack]
// );
// } catch (e) {
// console.error(e);
// if (body) console.error(body);
// }
// res.writeHead(201);
// res.end();
// });
// });
// server.listen(config.port);
console.log('server listening on', config.port);

View File

@ -1,8 +1,11 @@
<template>
<div id="app">
<div>
{{json}}
<table>
<LogEntry v-for="(value,key) in json" :key="key" :columns="value"></LogEntry>
<tr v-for="(row,rowKey) in json" :key="rowKey">
<td v-for="(value,key) in row" :key="key">{{value}}</td>
</tr>
</table>
</div>
<br />
@ -12,31 +15,12 @@
rel="license"
href="https://www.gnu.org/licenses/gpl-3.0.en.html"
>GNU General Public License v3.0 or later &copy; Timo Hocker</a>
<!--
<script>
fetch('?json')
.then(res => res.json())
.then(json => {
let data = '<table>';
for (let row of json) {
data += `<tr><td>${row.join('</td><td>')}</td></tr>`;
}
data += '</table>';
document.getElementById('data').innerHTML = data;
});
</script>
</body>
</html>
-->
</div>
</template>
<script>
import LogEntry from "./components/LogEntry.vue";
export default {
name: "App",
components: ["LogEntry"],
data: {
json: []
},
@ -45,6 +29,7 @@ export default {
.then(res => res.json())
.then(json => {
this.json = json;
console.log(this.json);
});
}
};

View File

@ -1,15 +0,0 @@
<template>
<tr>
<td v-for="(value,key) in columns" :key="key">{{value}}</td>
</tr>
</template>
<script>
export default {
name: "LogEntry",
props: ["columns"]
};
</script>
<style>
</style>