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
+2 -2
View File
@@ -69,12 +69,12 @@ app.use('/styles', express.static(path.resolve(__dirname + '/../public/styles'))
//the app file(s)
app.get('/*app.bundle.js', (req, res) => {
res.sendFile(path.resolve(`${__dirname}/../public/${req.originalUrl}`));
res.sendFile(path.resolve(`${__dirname}/../public/${req.originalUrl.split('/').pop()}`));
});
//fallback
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname + '/../public/index.html'));
res.sendFile(path.resolve(__dirname + '/../public/index.html'));
});
//startup
+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));