-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
54 lines (45 loc) · 1.1 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
'use strict';
const express = require('express'),
app = express(),
appConfig = require('./config/appConfig'),
authController = require('./api/auth/authController'),
bodyParser = require('body-parser'),
cookieParser = require('cookie-parser'),
expressSession = require('express-session');
/**
* Top Level Parser Settings
*/
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: false
}));
app.use(cookieParser());
/**
* Configure and Setup Sessions
*/
let sessionConfig = {
resave: true,
saveUninitialized: false,
secret: appConfig.secret
}
if (appConfig.sessionMaxAgeMs) {
sessionConfig.cookie.maxAge = appConfig.sessionMaxAgeMs;
}
if (app.get('env') === 'production') {
app.set('trust proxy', 1); // trust first proxy
sessionConfig.cookie.secure = true; // serve secure cookies
}
app.use(expressSession(sessionConfig));
/**
* Routing
*/
// Set layer /api of requests using api
const api = require('./api/apiRouter');
app.use('/api', api);
/**
* Serve Static Files
*/
if (appConfig.staticRoute) {
app.use(express.static(appConfig.staticRoute));
}
module.exports = app;