-
Notifications
You must be signed in to change notification settings - Fork 5
/
express.js
58 lines (46 loc) · 1.41 KB
/
express.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
var express = require ('express');
var cors = require('cors');
var parser = require('body-parser');
var passport = require('passport');
var session = require('express-session');
var config = require('./config/config.js');
var cookieParser = require('cookie-parser');
var mongoStore = require('connect-mongo')({
session: session
});
var path = require('path');
module.exports = function (db){
var app = new express();
// Globbing model files
config.getGlobbedFiles('./models/*.js').forEach(function(modelPath) {
require(path.resolve(modelPath));
});
app.set('port', (process.env.PORT || 3000));
// Setting the app router and static folder
app.use(express.static(path.resolve('public')));
app.use(cors())
.use(parser.urlencoded({ extended: true}))
.use(parser.json());
// CookieParser should be above session
app.use(cookieParser());
// Express MongoDB session storage
app.use(session({
saveUninitialized: true,
resave: true,
secret: config.sessionSecret,
store: new mongoStore({
mongooseConnection: db.connection
// collection: 'sessions'
})
}));
// use passport session
app.use(passport.initialize());
app.use(passport.session());
// Globbing routing files
config.getGlobbedFiles('./routes/*.js').forEach(function(routePath) {
require(path.resolve(routePath))(app);
});
// require('./routes/users.server.routes.js')(app);
// require('./routes/article.server.routes.js')(app);
return app;
}