diff options
author | ache <ache@ache.one> | 2019-11-16 01:50:33 +0100 |
---|---|---|
committer | ache <ache@ache.one> | 2019-11-16 01:50:33 +0100 |
commit | ba21f80d52c6b91cf01cf573bd73584df6e264d9 (patch) | |
tree | aa585c0fe9378b04f848a99650abe6cd5dcea3d9 | |
parent | Live modifications (diff) |
Beautifuller
-rw-r--r-- | app.js | 26 |
1 files changed, 16 insertions, 10 deletions
@@ -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 = '<html>'; @@ -113,6 +116,7 @@ app.get('*', (req, res) => { res.status(500).send(html); return; } + hmd(data, (err, file) => { if (err) { let html = '<html>'; @@ -124,6 +128,7 @@ app.get('*', (req, res) => { html += '</html>'; res.status(404).send(html); } + let html = '<html>'; html += '<head>'; html += `<style>${style}</style>`; @@ -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); }); |