-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
71 lines (60 loc) · 1.79 KB
/
main.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
66
67
68
69
70
71
"use strict";
const express = require("express"),
app = express(),
layouts = require("express-ejs-layouts"),
mongoose = require("mongoose"),
passport = require("passport"),
cookieParser = require("cookie-parser"),
expressSession = require("express-session"),
connectFlash = require("connect-flash"),
router = require("./routes/index"),
User = require("./models/user");
require('dotenv').config();
app.set("view engine", "ejs");
app.set("port", process.env.PORT || 3000);
//app.set('trust proxy', 1)
mongoose.connect(process.env.MONGO_DB_URI || "mongodb+srv://webDBUser:[email protected]/bookYourBooks?retryWrites=true&w=majority", (err)=>{
if(err) throw err;
console.log("DB Connected Successfully");
});
app.use(layouts);
app.use(express.static("public"));
app.use(
express.urlencoded({extended: false})
);
app.use(express.json());
// app.use(cookieParser("bookYourBooks"));
// app.use(
// expressSession({
// secret: "bookYourBooks",
// cookie: {
// maxAge: 4000000
// },
// resave: false,
// saveUninitialized: false
// })
// );
app.use(cookieParser("book your books"));
app.use(expressSession({
secret: 'book your books',
resave: false,
saveUninitialized: false,
cookie: {
maxAge: 4000000}
}));
app.use(connectFlash());
app.use(passport.initialize());
app.use(passport.session());
passport.use(User.createStrategy());
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());
app.use((req, res, next) => {
res.locals.loggedIn = req.isAuthenticated();
res.locals.currentUser = req.user;
res.locals.flashMessages = req.flash();
next();
});
app.use("/", router);
app.listen(app.get("port"), () => {
console.log(`Server running at http://localhost:${app.get("port")}`);
});