-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (31 loc) · 909 Bytes
/
index.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
39
import express from "express";
import bodyParser from "body-parser";
import { dirname } from "path";
import { fileURLToPath } from "url";
const app = express();
const port = 80;
const __dirname = dirname(fileURLToPath(import.meta.url));
var userIsAuthorised = false;
app.use(bodyParser.urlencoded({extended:true}));
function passwordCheck(req, res, next){
const password = req.body["password"];
if (password === "ravi"){
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");
}
});
app.listen(port, () =>{
console.log(`Listening on port ${port}`);
})