-
Notifications
You must be signed in to change notification settings - Fork 15
/
index.js
65 lines (53 loc) · 1.63 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
56
57
58
59
60
61
62
63
64
65
require("./config/database").connect();
const express = require("express");
const cookieParser = require("cookie-parser");
const bodyParser = require("body-parser");
const app = express();
const { PORT, MONGODB_URL, SESSION_SECRET_KEY } = process.env;
const expressLayouts = require("express-ejs-layouts");
// used for session cookie
const session = require("express-session");
const passport = require("passport");
const passportLocal = require("./config/passport-local-strategy");
const MongoStore = require("connect-mongo");
const flash = require("connect-flash");
const customMware = require("./config/middleware");
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(expressLayouts);
// set up view engine
app.set("view engine", "ejs");
app.set("views", "./views");
// mongo store is used to store the session cookie in the db
app.use(
session({
name: "placement-cell",
secret: SESSION_SECRET_KEY,
saveUninitialized: false,
resave: false,
cookie: {
maxAge: 1000 * 60 * 100,
},
store: MongoStore.create({
mongoUrl: MONGODB_URL,
autoRemove: "disabled",
}),
function(err) {
console.log(err || "connect-mongodb setup ok");
},
})
);
app.use(passport.initialize());
app.use(passport.session());
// sets the authenticated user in the response
app.use(passport.setAuthenticatedUser);
app.use(flash());
app.use(customMware.setFlash);
// use express router
app.use("/", require("./routes"));
app.listen(PORT || 5000, (err) => {
if (err) {
console.log(`Error in running the server: ${err}`);
}
console.log(`server is running on port: ${PORT}`);
});