-
Notifications
You must be signed in to change notification settings - Fork 153
/
main.js
75 lines (65 loc) · 1.86 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
72
73
74
75
"use strict";
const express = require("express"),
layouts = require("express-ejs-layouts"),
app = express(),
router = require("./routes/index"),
morgan = require("morgan"),
mongoose = require("mongoose"),
methodOverride = require("method-override"),
passport = require("passport"),
cookieParser = require("cookie-parser"),
expressSession = require("express-session"),
expressValidator = require("express-validator"),
connectFlash = require("connect-flash"),
User = require("./models/user");
mongoose.connect(
process.env.MONGODB_URI || "mongodb://localhost:27017/confetti_cuisine",
{ useNewUrlParser: true, useFindAndModify: false }
);
mongoose.set("useCreateIndex", true);
app.set("port", process.env.PORT || 3000);
app.set("view engine", "ejs");
app.use(
methodOverride("_method", {
methods: ["POST", "GET"]
})
);
app.use(morgan("combined"));
app.use(layouts);
app.use(express.static("public"));
app.use(expressValidator());
app.use(
express.urlencoded({
extended: false
})
);
app.use(express.json());
app.use(cookieParser("secretCuisine123"));
app.use(
expressSession({
secret: "secretCuisine123",
cookie: {
maxAge: 4000000
},
resave: false,
saveUninitialized: false
})
);
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);
const server = app.listen(app.get("port"), () => {
console.log(`Server running at http://localhost:${app.get("port")}`);
}),
io = require("socket.io")(server),
chatController = require("./controllers/chatController")(io);