From 0405443391230f56ba25db55758e5dd28eb6b8c7 Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Tue, 3 Sep 2019 12:24:50 +0200 Subject: [PATCH] fixes --- build.bat | 2 -- build.sh | 2 -- index.js | 61 +++------------------------------ web/src/App.vue | 25 +++----------- web/src/components/LogEntry.vue | 15 -------- 5 files changed, 10 insertions(+), 95 deletions(-) delete mode 100644 web/src/components/LogEntry.vue diff --git a/build.bat b/build.bat index 419f343..0f0c3c4 100644 --- a/build.bat +++ b/build.bat @@ -1,7 +1,5 @@ cd web -call npm ci call npm run build mkdir ../html robocopy ./dist ../html /MIR cd .. -npm ci diff --git a/build.sh b/build.sh index 86dd879..11cb42e 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,4 @@ cd web -npm ci npm run build cp -R ./dist ../html cd .. -npm ci diff --git a/index.js b/index.js index b92dbf7..f3f48dd 100644 --- a/index.js +++ b/index.js @@ -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); diff --git a/web/src/App.vue b/web/src/App.vue index 143bda7..538e842 100644 --- a/web/src/App.vue +++ b/web/src/App.vue @@ -1,8 +1,11 @@ - - \ No newline at end of file