-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
56 lines (41 loc) · 1.34 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
var bodyParser = require('body-parser'),
express = require('express'),
globSync = require('glob').sync,
routes = globSync('./routes/**/*.js', { cwd: __dirname }).map(require),
cluster = require('cluster'),
winston = require('winston'),
chalk = require('chalk'),
morgan = require('morgan');
require('./config/mongoose').init();
exports.init = function ( app ) {
winston.debug(chalk.dim('Setting server options...'));
app.enable('trust proxy');
app.set('x-powered-by', 'Associated Employers');
if( cluster.worker ) {
app.set('worker', cluster.worker.id);
}
winston.debug(chalk.dim('Setting up middleware...'));
var logRoute = ( process.env.environment === 'test' ) ? process.env.verboseLogging : true;
if( logRoute ) {
app.use( morgan('dev') );
}
app.use( bodyParser.json() );
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(function ( req, res, next ) {
if( app.settings.worker ) {
winston.debug(chalk.dim('Request served by worker', app.settings.worker));
}
next();
});
winston.debug(chalk.dim('Getting routes...'));
routes.forEach(function(route) {
route(app);
});
return app;
};
exports.registerModels = function () {
winston.debug(chalk.dim('Registering models...'));
globSync('./models/**/*.js').map(require);
};