index.js
1.6 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
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
/**
* Module dependencies.
*/
var Initializer = require('./initializer');
/**
* Make `app` bootable.
*
* This function makes an application bootable. Booting consists of executing
* a sequence of phases to initialize the application.
*
* Examples:
*
* var app = bootable(express());
* app.phase(bootable.initializers());
* app.phase(bootable.routes());
*
* app.boot(function(err) {
* if (err) { throw err; }
* app.listen(3001);
* });
*
* @param {Object} app
* @returns {Object} app
* @api public
*/
exports = module.exports = function (app, phases) {
phases = [].slice.call(arguments, 1);
// Mixin initializer.
app._initializer = new Initializer();
/**
* Boot application.
*
* @param {Function} cb
* @param {Object} [thisArg]
* @api public
*/
app.boot = function (cb, thisArg) {
this._initializer.run(cb, thisArg || this);
};
/**
* Add phase to boot sequence.
*
* @param {Function} fn
* @return {Object} for chaining
* @api public
*/
app.phase = function (fn) {
this._initializer.phase(fn);
return this;
};
// Register phases, if any.
for (var i = 0; i < phases.length; ++i) {
app.phase(phases[i]);
}
return app;
};
/**
* Export constructors.
*/
exports.Initializer = Initializer;
/**
* Export phases.
*/
exports.initializers = require('./phases/initializers');
exports.routes = require('./phases/routes');
/**
* Export dependency injection-capable phases.
*/
exports.di = require('./bootable-di');