-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
executable file
·51 lines (40 loc) · 1.24 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
/**
* Module dependencies
*/
var fs = require('fs');
var app = require('express')();
var passport = require('passport');
var env = process.env.NODE_ENV || 'development';
var methodOverride = require('method-override');
module.exports = function(config, db) {
app.use(function(req, res, next) {
if (env === 'development' || env === 'test') {
res.header("Access-Control-Allow-Origin", "*");
}
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
app.options('*', function(req, res) {
res.sendStatus(200);
});
app.use(methodOverride(function (req, res) {
if (req.body && typeof req.body === 'object' && '_method' in req.body) {
// look in urlencoded POST bodies and delete it
var method = req.body._method;
delete req.body._method;
return method;
}
}));
db(config);
// Bootstrap models
fs.readdirSync(__dirname + '/app/models').forEach(function (file) {
if (~file.indexOf('.js')) require(__dirname + '/app/models/' + file);
});
// Bootstrap passport config
require('./config/passport')(passport, config);
// Bootstrap application settings
require('./config/express')(app, passport);
// Bootstrap routes
require('./config/routes')(app, passport);
return app;
};