-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (32 loc) · 892 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
40
const express = require("express");
const authRoutes = require("./routes/authRoutes");
const homeRoutes = require("./routes/homeRoutes");
//session cookies
const app = express();
const session = require("express-session");
const mongoDBStore = require('connect-mongodb-session')(session);
const dbURL ="mongodb://localhost:27017";
const store = new mongoDBStore({
databaseName:"Session",
uri: dbURL,
collection: "session"
})
//Session Config
const sessionConfig = {
secret: "hackathonProject",
resave: false,
saveUninitialized: false,
store:store
};
app.use(session(sessionConfig));
app.use(express.urlencoded({extended:false}))
app.use(express.static("public"));
app.set("view engine","ejs");
app.set("views","view");
app.use(authRoutes);
app.use(function(req,res,next){
res.locals.isAuth = req.session.isAuth;
next();
})
app.use(homeRoutes)
app.listen(3000);