bootstrapper.js
2.15 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
79
80
81
82
83
84
/*
* bootstrapper.js: Default logic for bootstrapping broadway applications.
*
* (C) 2011, Nodejitsu Inc.
* MIT LICENSE
*
*/
var broadway = require('../broadway');
//
// ### bootstrap (app, callback)
// #### @app {broadway.App} Application to bootstrap
// #### @callback {function} Continuation to respond to when complete.
// Bootstraps the specified `app`.
//
exports.bootstrap = function (app) {
app.options['config'] = app.options['config'] || {};
app.options['config'].init = false;
app.use(broadway.plugins.config);
//
// Remove initializers run by the bootstrapper.
//
delete app.initializers['config'];
app.initlist.pop();
//
// Set the current environment in the config
//
app.config.set('env', app.env);
};
//
// ### bootstrap (app, callback)
// #### @app {broadway.App} Application to bootstrap
// #### @callback {function} Continuation to respond to when complete.
// Runs the initialization step of the bootstrapping process
// for the specified `app`.
//
exports.init = function (app, callback) {
broadway.plugins.config.init.call(app, function (err) {
if (err) {
return callback(err);
}
if (app.config.get('handleExceptions')) {
app.use(broadway.plugins.exceptions, app.options['exceptions'] || {});
}
app.use(broadway.plugins.directories, app.options['directories'] || {});
app.use(broadway.plugins.log, app.options['log'] || {});
//
// Ensure the `directories` and `log` plugins initialize before
// any other plugins. Since we cannot depend on ordering (if they were
// manually added) splice the specific indexes
//
var log = app.initlist.indexOf('log');
app.initlist.unshift.apply(
app.initlist,
app.initlist.splice(log)
);
var directories = app.initlist.indexOf('directories');
app.initlist.unshift.apply(
app.initlist,
app.initlist.splice(directories)
);
//
// Put the godot plugin before the log if it exists
//
var godot = app.initlist.indexOf('godot');
if(~godot) {
app.initlist.unshift.apply(
app.initlist,
app.initlist.splice(godot)
);
}
callback();
});
};