-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
64 lines (48 loc) · 1.64 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
57
58
59
60
61
62
63
64
const path = require('path');
const express = require('express');
const logger = require('morgan');
const bodyParser = require('body-parser');
const methodOverride = require('method-override');
const cookieParser = require('cookie-parser');
const session = require('express-session');
const MongoStore = require('connect-mongo')(session);
const helmet = require('helmet');
const log = require('winston');
const env = require('./config/env');
if (env.node_env === 'production') require('newrelic');
// config bluebird
require('./config/bluebird');
// config mongoose
const mongoose = require('./config/mongoose');
// config passport
const passport = require('./config/passport');
const app = express();
// view engine setup
app.set('views', path.join(__dirname, 'app/views'));
app.set('view engine', 'jade');
app.locals.moment = require('moment');
app.disable('x-powered-by');
app.use(helmet());
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(methodOverride('_method'));
const { secret } = env;
app.use(cookieParser(secret));
app.use(session({
secret,
store: new MongoStore({ mongooseConnection: mongoose.connection }),
saveUninitialized: true,
resave: false,
}));
app.use(express.static(path.join(__dirname, 'app/public')));
app.use('/doc', express.static(path.join(__dirname, 'doc')));
app.use(passport.initialize());
app.use(passport.session());
require('./config/routes')(app);
app.set('port', env.port);
const server = app.listen(app.get('port'), () => {
log.info(`Express server worker listening on port ${app.get('port')}`);
});
require('./config/io')(server);
module.exports = app;