Add 404 error support

This commit is contained in:
Ethanell 2020-04-26 19:20:51 +02:00
parent e30e92f9ce
commit 6e66b84cdd
2 changed files with 11 additions and 2 deletions

8
app.js
View file

@ -92,12 +92,16 @@ app.use(morgan("dev"))
res.redirect("/login?fail");
}
})
.get("/images/:name", (req, res) => {
.get("/images/:name", (req, res, next) => {
if ("name" in req.params && fs.existsSync("./images/"+req.params.name)) {
res.sendfile("./images/"+req.params.name);
} else {
res.status(404).send("Image not found :/");
next();
}
})
.use((req, res) => {
res.status(404);
res.render("404", {url: req.path});
})
.listen(8080);

5
views/404.pug Normal file
View file

@ -0,0 +1,5 @@
extend layout
block content
h1 404 - Page not found
p The requested URL #{url} was not found on this server