Implemented news page, wrote moderation post

This commit is contained in:
2019-06-05 08:02:43 +10:00
parent b5286e1c22
commit 6bbcd03179
9 changed files with 97 additions and 4 deletions
+18 -1
View File
@@ -11,6 +11,23 @@ const newsRequest = () => (req, res) => {
let fpath = path.join(__dirname, '..', 'public', 'news');
let fileNames = fs.readdirSync(fpath);
//if it's one specific post
if (req.body.postId) {
if (!fileNames.includes(req.body.postId)) {
res.status(404).write('File Not Found');
res.end();
return;
}
let json = {};
json[req.body.postId] = fs.readFileSync(path.join(fpath, req.body.postId), 'utf8');
res.status(200).json(json);
res.end();
log('News sent (singular)', req.body.postId, JSON.stringify(json));
return;
}
//set the maximum
let max = parseInt(req.body.length) || 99;
if (isNaN(max) || max > fileNames.length) {
@@ -26,7 +43,7 @@ const newsRequest = () => (req, res) => {
}
//actually send the data
res.json(json);
res.status(200).json(json);
res.end();
log('News sent', max, fileNames, JSON.stringify(json));