-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.js
38 lines (31 loc) · 900 Bytes
/
solution.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import express from "express";
import bodyParser from "body-parser";
import { dirname } from "path";
import { fileURLToPath } from "url";
const __dirname = dirname(fileURLToPath(import.meta.url));
const app = express();
const port = 3000;
var userIsAuthorised = false;
app.use(bodyParser.urlencoded({ extended: true }));
function passwordCheck(req, res, next) {
const password = req.body["password"];
if (password === "ILoveProgramming") {
userIsAuthorised = true;
}
next();
}
app.use(passwordCheck);
app.get("/", (req, res) => {
res.sendFile(__dirname + "/public/index.html");
});
app.post("/check", (req, res) => {
if (userIsAuthorised) {
res.sendFile(__dirname + "/public/secret.html");
} else {
res.sendFile(__dirname + "/public/index.html");
//Alternatively res.redirect("/");
}
});
app.listen(port, () => {
console.log(`Listening on port ${port}`);
});