aboutsummaryrefslogtreecommitdiff
path: root/app.js
diff options
context:
space:
mode:
Diffstat (limited to 'app.js')
-rw-r--r--app.js46
1 files changed, 21 insertions, 25 deletions
diff --git a/app.js b/app.js
index 5d19e75..eb95838 100644
--- a/app.js
+++ b/app.js
@@ -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');
@@ -26,20 +26,16 @@ const multiChoice = require('remark-multiple-choice');
const lineInput = require('remark-line-input');
const select = require('remark-select');
const textInput = require('remark-text-input');
-
const raw = require('rehype-raw');
const rehypeKatex = require('rehype-katex');
const rehypeStringify = require('rehype-stringify');
-
const unified = require('unified');
const remark = require('remark-parse');
-const inspect = require('unist-util-inspect');
-
const useLandScript = '';
-const userSide_Button = '<button class="raw_button" ><div><div>Raw</div></div></button></form>';
+const rawButton = '<button class="raw_button" ><div><div>Raw</div></div></button></form>';
-function to_HTML(data, fnc) {
+function toHTML(data, fnc) {
unified()
.use(remark)
.use(lineInput)
@@ -64,15 +60,15 @@ app.get('/' + path + '/*', (req, res) => {
const url = decodeURI(req._parsedUrl.pathname);
const query = req.query;
- console.log('[' + new Date() + '] > ' + '200 - ' + url);
- if (query && query.raw == 'true') {
+ console.log('[' + new Date() + '] > ' + 200 + ' - ' + url);
+ if (query && query.raw === 'true') {
res.sendFile(url, {root: '.',
dotfiles: 'deny',
headers: {
'x-timestamp': Date.now(),
'x-sent': true}}, err => {
if (err) {
- next(err);
+ console.log('Error : ', err);
} else {
console.log('Sent : ', url);
}
@@ -96,27 +92,27 @@ app.get('/' + path + '/*', (req, res) => {
console.log(inspect(a));
*/
- to_HTML(data, (err, file) => {
+ toHTML(data, (err, file) => {
res.send(String(file) + useLandScript +
- '<a href="' + url + '?raw=true" class="no-style">' + userSide_Button + '</a>');
+ '<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);
- if (path == '/img/ic_info_black_48px.svg' ||
- path == '/imr/ic_error_black_48px.svg' ||
- path == '/imr/ic_good_black_48px.svg' ||
- path == '/imr/ic_bad_black_48px.svg' ||
- path == '/imr/ic_comment_black_48px.svg' ||
- path == '/imr/ic_help_black_48px.svg') {
+ 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' ||
+ path === '/imr/ic_bad_black_48px.svg' ||
+ path === '/imr/ic_comment_black_48px.svg' ||
+ path === '/imr/ic_help_black_48px.svg') {
const img = fs.readFileSync(path);
res.writeHead(200, {'Content-Type': 'image/svg'});
res.end(img, 'binary');
@@ -128,7 +124,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);
@@ -138,13 +134,13 @@ 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) => {
- to_HTML(data, (err, file) => {
+ toHTML(data, (err, file) => {
let html = '<html>';
html += '<head>';
html += '<style>' + style + '</style>';
@@ -159,8 +155,8 @@ app.get('*', (req, res) => {
});
});
-var server = app.listen(8090, () => {
+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);
});