-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
55 lines (43 loc) · 1.19 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
52
53
54
55
// require configuration file
require('dotenv').config()
// import packages
let express = require('express')
let path = require('path')
let favicon = require('serve-favicon')
let mongoose = require('mongoose')
let cookieParser = require('cookie-parser')
let session = require('express-session')
let flash = require('connect-flash')
let bodyParser = require('body-parser')
let route = require('./_routes/web')
// database
let db = require('./database/db')
// init express
let app = express();
// init pug
app.set('view engine', 'pug')
// set public static path
app.use(express.static(path.join(__dirname, './public')))
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
// init body-parser
app.use(cookieParser())
// init app session
app.use(session({
secret: 'lizards',
resave: true,
saveUninitialized: true,
cookie: { secure: true }
}))
// init connect flash
app.use(flash());
// set flash middleware
app.use(function (req, res, next){
res.locals.flashes = req.flash();
next();
});
// routes web entry
app.use('/', route)
// export app to entry
module.exports = app