From ba21f80d52c6b91cf01cf573bd73584df6e264d9 Mon Sep 17 00:00:00 2001 From: ache Date: Sat, 16 Nov 2019 01:50:33 +0100 Subject: Beautifuller --- app.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/app.js b/app.js index 9b49378..81ad45a 100644 --- a/app.js +++ b/app.js @@ -21,7 +21,7 @@ app.use(express.static('public')); app.get(`/${path}/*`, (req, res) => { const url = decodeURI(req._parsedUrl.pathname); - const query = req.query; + const {query} = req; console.log(`[${new Date()}] > ${200} - ${url}`); if (query && query.raw === 'true') { @@ -34,17 +34,17 @@ app.get(`/${path}/*`, (req, res) => { }, }, err => { if (err) { - console.log('Error : ', err); + console.error(`Error: ${err}`); } else { - console.log('Sent : ', url); + console.log(`Sent: ${url}`); } - } - ); + }); return; } + fs.readFile(url.substr(1), 'utf8', (err, data) => { if (err) { - return console.log(err); + return console.error(err); } hmd(data, (err, file) => { @@ -82,8 +82,9 @@ app.get('/', (req, res) => { console.log(`[${new Date()}] > ${200} - ${req.url}`); fs.readFile('public/index.html', 'utf8', (err, data) => { if (err) { - return console.log(err); + return console.error(err); } + res.send(data); }); }); @@ -91,8 +92,9 @@ app.get('/edit', (req, res) => { console.log(`[${new Date()}] > ${200} - ${req.url}`); fs.readFile('public/edit.html', 'utf8', (err, data) => { if (err) { - return console.log(err); + return console.error(err); } + res.send(data); }); }); @@ -100,8 +102,9 @@ app.get('*', (req, res) => { console.error(`[${new Date()}] > ${404} - ${req.url}`); fs.readFile('public/404.md', 'utf8', (err, data) => { if (err) { - return console.log(err); + return console.error(err); } + fs.readFile('public/css/style.css', 'utf8', (err, style) => { if (err) { let html = ''; @@ -113,6 +116,7 @@ app.get('*', (req, res) => { res.status(500).send(html); return; } + hmd(data, (err, file) => { if (err) { let html = ''; @@ -124,6 +128,7 @@ app.get('*', (req, res) => { html += ''; res.status(404).send(html); } + let html = ''; html += ''; html += ``; @@ -140,6 +145,7 @@ app.get('*', (req, res) => { const server = app.listen(8090, () => { const host = server.address().address; - const port = server.address().port; + const {port} = server.address(); + console.log(`[${new Date()}] > App listening at http://%s:%s`, host, port); }); -- cgit v1.2.3