main app loading articles in memory

This commit is contained in:
Klemek
2019-06-19 20:17:00 +02:00
parent f335cb9f13
commit 94d96df26f
2 changed files with 37 additions and 6 deletions
+36 -2
View File
@@ -1,11 +1,45 @@
const express = require('express');
const app = express();
module.exports = (/*config*/) => {
app.get('/', (req,res) => {
const cons = {
ok: '\x1b[32m✔\x1b[0m %s',
warn: '\x1b[33m⚠\x1b[0m %s',
error: '\x1b[31m✘\x1b[0m %s',
};
module.exports = (config) => {
const fw = require('./file_walker')(config);
const articles = [];
const reload = (callback) => {
fw.fetchArticles((err, list) => {
if (err) {
callback(false);
return console.error(cons.error, 'loading articles : ' + err);
}
articles.splice(0, articles.length, ...list);
if (articles.length > 0)
console.log(cons.ok, `loaded ${articles.length} article${articles.length > 1 ? 's' : ''}`);
else
console.log(cons.warn, `no articles loaded, check your configuration`);
callback(true);
});
};
app.get('/', (req, res) => {
res.status(200).send('Hello World!');
});
app.start = () => {
reload((res) => {
if (res)
app.listen(config['node_port'], () => {
console.log(cons.ok, `gitblog.md server listening on port ${config['node_port']}`);
});
});
};
return app;
};
+1 -4
View File
@@ -1,7 +1,4 @@
const config = require('./config')();
const app = require('./app')(config);
app.listen(config['node_port'], () => {
console.log(`gitblog.md server listening on port ${config['node_port']}`);
});
app.start();