Gracefully handle fetching non-existing guides

This commit is contained in:
Yarmo Mackenbach 2021-03-09 11:05:59 +01:00
parent a0fbbb698b
commit 2cfe8a7244
No known key found for this signature in database
GPG key ID: 37367F4AF4087AD1

View file

@ -69,12 +69,21 @@ router.get('/guides', (req, res) => {
router.get('/guides/:guideId', (req, res) => {
let env = {};
let rawContent = fs.readFileSync(`./content/guides/${req.params.guideId}.md`, "utf8", (err, data) => {
if (err) throw err;
return data;
fs.readFile(`./content/guides/${req.params.guideId}.md`, "utf8", (err, data) => {
if (err) {
res.render(`404`);
return
}
const content = md.render(data, env);
res.render(`basic`, { title: `${env.title} - Keyoxide`, content: content });
});
const content = md.render(rawContent, env);
res.render(`basic`, { title: `${env.title} - Keyoxide`, content: content });
// let rawContent = fs.readFileSync(`./content/guides/${req.params.guideId}.md`, "utf8", (err, data) => {
// if (err) throw err;
// return data;
// });
// const content = md.render(rawContent, env);
// res.render(`basic`, { title: `${env.title} - Keyoxide`, content: content });
});
module.exports = router;