-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathapp.js
56 lines (45 loc) · 1.43 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
56
const express = require('express');
const session = require('express-session');
const path = require('path');
const helmet = require('helmet');
const Config = require('./libs/config');
const common = require('./common');
const app = express();
app.use(helmet());
//================= Templates
app.set('views', __dirname + '/templates');
app.set('view engine', 'ejs');
app.set('view options', {compileDebug: false, self: true, cache: true});
app.use(express.static(path.join(__dirname, 'public')));
//================= Session
const sessionStore = require('./libs/sessionStore');
app.use(session({
secret: Config.session.secret,
key: Config.session.key,
cookie: Config.session.cookie,
store: sessionStore,
resave: false,
saveUninitialized: true
}));
//================= Social Auth
const passport = require('passport');
require('./libs/passport')(passport);
app.use(passport.initialize());
app.use(passport.session());
//================= Common middleware
app.use(common.commonMW);
//================= Routing
require('./routes')(app, passport);
//================= Error handling
app.use((err, req, res, next) => {
console.error('Error:', err.stack);
res.status(502);
res.render('./error', {errorMsg: 'Server Error'});
});
app.use((req, res) => {
res.status(404);
res.render('./error', {errorMsg: 'Not Found'});
});
app.listen(Config.port, () => {
console.log(`Listening on port ${Config.port}!`);
});