-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlifecycle.js
73 lines (61 loc) · 1.57 KB
/
lifecycle.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
var bodyparser = require('body-parser');
var path = require('path');
module.exports = function (app) {
var cfg = app.cfg;
return {
/**
* basic settings
*/
settings: function () {
this._before('settings');
app.set('port', 8001);
if(cfg.root){
app.set('root', cfg.root);
}else{
app.cfg.root = app.get('root');
}
// app.set('www', app.get('root') + "/" + app.get('public'));
if (cfg.public) {
app.set_key_with_setting_key('public', 'public');
}
if (cfg.views) {
app.set_key_with_setting_key('views', 'views');
}
this._after('settings');
},
/**
* global middlewares
*/
global_middlewares: function () {
this._before('global_middlewares');
// default = base2-express-middlewares
app.mount_plugins(__dirname + '/node_modules/base2-' + app.cfg.type + '-middlewares/lib');
this._after('global_middlewares');
},
/**
* routes
*/
routes: function () {
this._before('routes');
// ...
if (cfg.routes) {
app.set('routes', cfg.routes);
app.mount_routes(app.cfg.root + "/" + cfg.routes, app.debug);
}
this._after('routes');
},
_call:function(type,method){
var cfg = app.cfg;
var m = cfg[type + '_' + method];
if (m) {
m(app);
}
},
_before:function(method){
this._call('before', method);
},
_after:function(method){
this._call('after', method);
}
}
}