app.js
1.1 KB
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
// # app
var path = require('path');
var IoC = require('electrolyte');
var bootable = require('bootable');
var express = require('express');
// change the working directory to the root directory
process.chdir(__dirname);
// dependency injection
IoC.loader(IoC.node(path.join(__dirname, 'boot')));
IoC.loader('igloo', require('igloo'));
IoC.loader('controllers', IoC.node(path.join(__dirname, 'controllers')));
IoC.loader('services', IoC.node(path.join(__dirname, 'services')));
IoC.loader('models', IoC.node(path.join(__dirname, 'models')));
IoC.loader('utils',IoC.node(path.join(__dirname, 'utils')));
// phases
var app = bootable(express());
app.phase(bootable.di.initializers());
app.phase(bootable.di.routes('./routes/bootstarp.js'));
app.phase(IoC.create('igloo/server'));
// boot
var logger = IoC.create('igloo/logger');
var settings = IoC.create('igloo/settings');
app.boot(function(err) {
if (err) {
logger.debug(err.message);
if (settings.showStack) {
logger.debug(err.stack);
}
process.exit(-1);
return;
}
logger.debug('app booted');
});
exports = module.exports = app;