-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
46 lines (40 loc) · 1020 Bytes
/
server.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
import express from "express";
import redis from "redis";
import session from "express-session";
import connectRedis from "connect-redis";
import dotenv from 'dotenv';
dotenv.config();
const app = express();
const port = 3000;
const RedisStore = connectRedis(session);
const client = redis.createClient({
host: "127.0.0.1",
port: 6379,
password: process.env.REDISPASS,
});
const sessionMiddleware = session({
store: new RedisStore({ client }),
secret: "something",
resave: false,
saveUninitialized: false,
cookie: {
secure: false,
httpOnly: false,
maxAge: 600000,
},
});
app.use(sessionMiddleware);
app.use(express.json());
app.get("/", async (req, res) => {
if (req.session) {
console.log(req.session.id);
await client.connect();
let sessionStored = await client.get("[email protected]")
console.log(sessionStored)
console.log("Done")
}
res.send({ message: "Hello world" });
});
app.listen(port, () => {
console.log(`Listening on port: ${port}`);
});