-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (39 loc) · 1.23 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const express = require("express");
const cookieParser = require('cookie-parser');
const ConfigLoader = require("./config/ConfigLoader");
const app = express();
app.use(cookieParser());
const configLoader = new ConfigLoader();
configLoader.loadConfig(app);
app.get("/check", async (req, res) => {
console.log("check call")
const session = await req.getSession(false);
let id = "null";
if (session) id = await session.getAttribute("id");
res.send(id);
});
app.get("/log-in", async (req, res) => {
console.log("login call")
const query = req.query;
const session = await req.getSession();
const id = query.id;
const password = query.password;
const name = query.name;
if (session) {
await session.setAttribute("id", id);
await session.setAttribute("password", password);
await session.setAttribute("name", name);
}
let result = "null";
if (session) result = session.getAttribute("id")
res.send(result);
});
app.get("/log-out", async (req, res) => {
console.log("logout call")
req.removeSession();
const session = await req.getSession(false);
let id;
if (session) id = session.getAttribute("id");
res.send(id);
});
app.listen(3001);