Implemented news page, wrote moderation post
This commit is contained in:
+2
-2
@@ -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
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user