-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
40 lines (32 loc) · 1.09 KB
/
app.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
var express = require("express"),
app = express(),
passport = require("passport"),
LocalStrategy = require("passport-local"),
bodyParser = require("body-parser"),
User = require("./models/user"),
routes = require("./routes"),
config = require("./config"),
mongoose = require("mongoose");
app.set("view engine", "ejs");
app.use(bodyParser.urlencoded({ extended: true }));
mongoose.connect(`mongodb://${config.DB_SERVER}/${config.DB_NAME}`);
app.use(require("express-session")({
secret: config.SESSION_SECRET,
resave: false,
saveUninitialized: false
}))
app.use(passport.initialize());
app.use(passport.session());
passport.use(new LocalStrategy(User.authenticate()));
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());
app.use((req, res, next) => {
res.locals.currentUser = req.user;
next();
})
app.use(routes);
app.use(express.static(__dirname + "/public/ElaAdmin"));
app.use(express.static(__dirname + "/public"));
app.listen(config.PORT, () => {
console.log(`Server has started on ${config.PORT}`);
})