-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.js
107 lines (84 loc) · 2.69 KB
/
bootstrap.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
module.exports = {
_register : null,
run : function (){
this
._initRegister()
._initAcl()
._initApplicationConfig()
._initApp()
._initLang()
._initRoutes()
._createServer()
;
},
_initRegister : function (){
global.register = require(global.LIB_PATH + '/register');
this._register = global.register;
return this;
},
_initAcl : function (){
var Acl = require('acl');
var acl = new Acl(new Acl.memoryBackend());
acl.allow('root', 'blogs', '*', function () {
acl.addUserRoles('jangot', 'root', function () {
console.log('Acl ok');
});
});
this._register.setAcl(acl);
return this;
},
_initApplicationConfig : function (){
this._register.setConfig(require(__dirname + '/conf/application'));
return this;
},
_initApp : function (){
var express = require('express');
var http = require('http');
var path = require('path');
var app = express();
app.configure(function(){
app.set('port', 3000);
app.set('views', global.VIEWS_PATH);
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser('101010'));
app.use(express.session());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
});
app.configure('development', function(){
app.use(express.errorHandler());
});
this._register.setApplication(app);
return this;
},
_initLang : function (){
var Lang = require(global.LIB_PATH + '/lang');
var lang = new Lang();
lang.addList(require('./langs/ru'));
this._register.setLang(Lang);
return this;
},
_initRoutes : function (){
var Router = require(global.LIB_PATH + '/routesLoader');
var app = global.register.getApplication();
var routes = new Router(app);
routes
.setFolder(__dirname + '/routes')
.setIndicator('')
.listen()
;
return this;
},
_createServer : function (){
var http = require('http');
var app = global.register.getApplication();
http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
});
return this;
}
}