-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·82 lines (65 loc) · 1.44 KB
/
server.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
var TAG = 'server';
/**
* Module dependencies
*/
var async = require('async');
/**
* Global App Object
*/
var app = {
config: require('./config/config'),
};
/**
* Define Globals
*/
global.app = app;
global._ = require('lodash');
/*
* Bootstrap Process
*/
var configSetps = [
// Setup Logging
require('./config/log'),
// Connect to DB
require('./config/mongoose'),
// Bootstrap Helpers
require('./config/helpers'),
// Bootstrap Models
require('./config/models'),
// Bootstrap Controllers
require('./config/controllers'),
// Bootstrap application settings
require('./config/express'),
// Start static serving on /public folder
require('./config/express-assets'),
// Bootstrap API routes
require('./config/routes/api'),
// Bootstrap routes
require('./config/routes'),
// Start Server
require('./config/lift'),
];
/*
This is the Lift hook, that
allows Tests to wait for lift.
*/
var onLift = null;
var lifted = false;
module.exports = function setLiftCallback(callback){
onLift = callback;
// Maybe, it's already lifted.
if(lifted) process.nextTick(onLift);
}
// Configure steps and initialize
async.eachSeries(configSetps, function (config, next){
config(app, next);
}, function (err){
if(err){
app.error(TAG, 'Failed to initialize Server: %s', err);
throw err;
}else{
app.info(TAG, 'Server lifted on port', app.config.port, '['+app.config.env+']');
lifted = true;
onLift && process.nextTick(onLift);
}
});