-
Notifications
You must be signed in to change notification settings - Fork 14
/
app.js
42 lines (33 loc) · 1.22 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
var utils = require('utils')
, chalk = require('chalk')
, env = utils.bootstrapEnv()
, app = env.app
, debug = env.debug
, helpers = utils.helpers
, bodyParser = require('body-parser')
, moduleLoader = env.moduleLoader;
moduleLoader.on('beforeLoad', function setupExpress() {
debug('Configuring express application...');
app.use(require('morgan')('dev'));
app.use(require('response-time')());
app.use(require('method-override')());
app.use(require('cors')(env.config.cors));
app.use(require('compression')());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
});
moduleLoader.on('modulesLoaded', function initializeRoutes() {
debug('Initializing routes...');
moduleLoader.initializeRoutes();
});
moduleLoader.on('routesInitialized', function startApp() {
debug('Starting http server...');
app.listen(env.webPort, function appReady() {
debug('Listening on port %s', chalk.yellow(env.webPort));
});
});
debug('Loading %s hook files...', chalk.yellow('app.js'));
helpers.loadModulesFileByName(__filename, env.config, require('cluster'), debug);
debug('Loading modules...');
moduleLoader.loadModules();
module.exports = app;