diff options
author | ache <ache@ache.one> | 2018-02-04 04:49:32 +0100 |
---|---|---|
committer | ache <ache@ache.one> | 2018-02-04 04:49:32 +0100 |
commit | 5ef5b666c2caa7961523f5566d0f480d564dd7fb (patch) | |
tree | e0ed1baf734f86ccc67613244147debbc09eda30 /app.js | |
parent | XO fix (diff) |
Work on the style guideline
Diffstat (limited to 'app.js')
-rw-r--r-- | app.js | 98 |
1 files changed, 61 insertions, 37 deletions
@@ -8,7 +8,7 @@ const path = 'md'; const app = express(); process.on('uncaughtException', err => { - console.error('[' + new Date() + '] > Error - ' + err); + console.error(`[${new Date()}] > Error - ${err}`); }); const report = require('vfile-reporter'); @@ -37,42 +37,46 @@ const rawButton = '<button class="raw_button" ><div><div>Raw</div></div></button function toHTML(data, fnc) { unified() - .use(remark) - .use(lineInput) - .use(textInput) - .use(select) - .use(multiChoice) - .use(math) - .use(kbd) - .use(sb) - .use(highlight) - .use(html, {allowDangerousHTML: true}) - .use(rehypeKatex) - .use(raw) - .use(rehypeStringify) - - .process(data, fnc); + .use(remark) + .use(lineInput) + .use(textInput) + .use(select) + .use(multiChoice) + .use(math) + .use(kbd) + .use(sb) + .use(highlight) + .use(html, {allowDangerousHTML: true}) + .use(rehypeKatex) + .use(raw) + .use(rehypeStringify) + + .process(data, fnc); } app.use(express.static('public')); -app.get('/' + path + '/*', (req, res) => { +app.get(`/${path}/*`, (req, res) => { const url = decodeURI(req._parsedUrl.pathname); const query = req.query; - console.log('[' + new Date() + '] > ' + 200 + ' - ' + url); + console.log(`[${new Date()}] > ${200} - ${url}`); if (query && query.raw === 'true') { - res.sendFile(url, {root: '.', + res.sendFile(url, { + root: '.', dotfiles: 'deny', headers: { 'x-timestamp': Date.now(), - 'x-sent': true}}, err => { - if (err) { - console.log('Error : ', err); - } else { - console.log('Sent : ', url); - } - }); + 'x-sent': true, + }, + }, err => { + if (err) { + console.log('Error : ', err); + } else { + console.log('Sent : ', url); + } + } + ); return; } fs.readFile(url.substr(1), 'utf8', (err, data) => { @@ -80,8 +84,8 @@ app.get('/' + path + '/*', (req, res) => { return console.log(err); } -// Remark() - /* Debbug comment + // Remark() + /* Debbug comment const a = unified() .use(remark) .use(lineInput) @@ -93,20 +97,20 @@ app.get('/' + path + '/*', (req, res) => { */ toHTML(data, (err, file) => { - res.send(String(file) + useLandScript + - '<a href="' + url + '?raw=true" class="no-style">' + rawButton + '</a>'); + res.send(`${String(file) + useLandScript + }<a href="${url}?raw=true" class="no-style">${rawButton}</a>`); console.error(report(err || file)); }); }); }); app.get('/data', (req, res) => { - console.log('[' + new Date() + '] > ' + 200 + ' - ' + req.url); + console.log(`[${new Date()}] > ${200} - ${req.url}`); res.send(dirTree(path, {extensions: /\.md/})); }); app.get('/img/*', (req, res) => { - console.log('[' + new Date() + '] > ' + 200 + ' - ' + req.url); + console.log(`[${new Date()}] > ${200} - ${req.url}`); if (path === '/img/ic_info_black_48px.svg' || path === '/imr/ic_error_black_48px.svg' || path === '/imr/ic_good_black_48px.svg' || @@ -124,7 +128,7 @@ app.get('/img/*', (req, res) => { }); app.get('/', (req, res) => { - console.log('[' + new Date() + '] > ' + 200 + ' - ' + req.url); + console.log(`[${new Date()}] > ${200} - ${req.url}`); fs.readFile('public/index.html', 'utf8', (err, data) => { if (err) { return console.log(err); @@ -134,18 +138,38 @@ app.get('/', (req, res) => { }); app.get('*', (req, res) => { - console.error('[' + new Date() + '] > ' + 404 + ' - ' + req.url); + console.error(`[${new Date()}] > ${404} - ${req.url}`); fs.readFile('public/404.md', 'utf8', (err, data) => { if (err) { return console.log(err); } fs.readFile('public/css/style.css', 'utf8', (err, style) => { + if (err) { + let html = '<html>'; + html += '<body>'; + html += '<h1>500 - Internal Server Error</h1>'; + html += `Debug : ${err}`; + html += '</body>'; + html += '</html>'; + res.status(500).send(html); + return; + } toHTML(data, (err, file) => { + if (err) { + let html = '<html>'; + html += '<body>'; + html += '<h1>500 - Internal Server Error</h1>'; + html += 'Debug : 404 page can\'t be converted to HTML<br>'; + html += `Debug : ${err}`; + html += '</body>'; + html += '</html>'; + res.status(404).send(html); + } let html = '<html>'; html += '<head>'; - html += '<style>' + style + '</style>'; + html += `<style>${style}</style>`; html += '</head>'; - html += '<body class=\'markdown-preview\' data-use-github-style>'; + html += '<body class=\'markdown-preview\'>'; html += String(file); html += '</body>'; html += '</html>'; @@ -158,5 +182,5 @@ app.get('*', (req, res) => { const server = app.listen(8090, () => { const host = server.address().address; const port = server.address().port; - console.log('[' + new Date() + '] > App listening at http://%s:%s', host, port); + console.log(`[${new Date()}] > App listening at http://%s:%s`, host, port); }); |