-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
51 lines (42 loc) · 1.36 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
41
42
43
44
45
46
47
48
49
50
51
const express = require('express');
// const bodyParser = require('body-parser');
const flash = require('connect-flash');
const mongoose = require('mongoose');
const session = require('express-session');
const passport = require('passport');
const cookieParser = require('cookie-parser');
const constants = require('./config/constants');
require('./config/passport')(passport);
mongoose.connect(process.env.MONGO_CONNECTION_STRING, {
dbName: 'testDB',
useNewUrlParser: true,
useFindAndModify: false,
useCreateIndex: true,
useUnifiedTopology: true,
});
const app = express();
app.set('view engine', 'ejs');
app.use(express.static(__dirname + '/public'));
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser(process.env.COOKIES_SECRET));
app.use(
session({
secret: process.env.SECRET,
resave: true,
saveUninitialized: true
})
);
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
app.use((req, res, next) => {
res.locals.user = req.user;
res.locals.PRESENT = constants.PRESENT;
res.locals.ABSENT = constants.ABSENT;
res.locals.MIN_DATE = constants.MIN_DATE;
res.locals.success_msgs = req.flash('success_msgs');
res.locals.error_msgs = req.flash('error_msgs');
next();
});
app.use('/', require('./routes/routes'));
app.listen(process.env.PORT, process.env.IP);