Add acces to image from url

This commit is contained in:
Ethanell 2020-04-26 19:12:25 +02:00
parent 7d4460b46e
commit db7eabaa67

10
app.js
View file

@ -80,7 +80,8 @@ app.use(morgan("dev"))
fail = true; fail = true;
} }
res.render("login", {title: "login", fail: fail}); res.render("login", {title: "login", fail: fail});
}).post("/login", (req, res) => { })
.post("/login", (req, res) => {
if ("username" in req.body && "password" in req.body) { if ("username" in req.body && "password" in req.body) {
file = JSON.parse(fs.readFileSync("users.json")); file = JSON.parse(fs.readFileSync("users.json"));
if (req.body.username in file && passwordHash.verify(req.body.password, file[req.body.username])) { if (req.body.username in file && passwordHash.verify(req.body.password, file[req.body.username])) {
@ -94,5 +95,12 @@ app.use(morgan("dev"))
res.redirect("/login?fail"); res.redirect("/login?fail");
} }
}) })
.get("/images/:name", (req, res) => {
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 :/");
}
})
.listen(8080); .listen(8080);