-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
57 lines (45 loc) · 1.22 KB
/
app.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const express = require("express");
const app = express();
const jsonParser = require ("body-parser").json();
const session = require("express-session");
app.set("view engine", "ejs");
app.set("views", "./views");
app.use(
session({
secret: "123345665454",
resave: false,
saveUninitialized: true,
cookie: {
maxAge: 1000 * 60 * 2
}
})
)
app.use(express.static('public'));
app.get("/try", (req, res) => {
res.send("Hellllo");
});
app.post("/axios", jsonParser, (req, res)=>{
res.send(req.body);
});
app.post("/signIn", jsonParser, (req, res)=>{
let { username, password } = req.body;
if(username === "thong" && password === "1234"){
req.session.username = username;
return res.send("DANG_NHAP_THANH_CONG");
}
res.send("DANG_NHAP_THAT_BAI");
});
app.get('/getInfo', (req, res) => {
if(req.session.username){
return res.send(req.session.username);
}
res.send("CHUA_DANG_NHAP");
});
app.get('/logout', (req, res) => {
req.session.username = undefined;
res.send("DA_DANG_XUAT");
});
app.use("/", require("./controller/HomeController"));
app.listen(3000, () => {
console.log("Server listen");
});