forked from adamrenklint/asimov-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (39 loc) · 1.18 KB
/
index.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
var cl = require('cluster');
if (cl.isWorker) process.env.ROLE = 'server_worker';
var asimov = require('asimov');
asimov.config('IS_SERVER_WORKER', cl.isWorker);
module.exports = function plugin () {
[
'premiddleware',
'middleware',
'postmiddleware'
].forEach(function (name) {
asimov.addSequence(name);
});
var port = process.env.PORT ? parseInt(process.env.PORT, 10) : 3003;
var pipeline = require('./lib/pipeline');
asimov
.register('requestData', pipeline.requestData)
.register('handleDataRequest', pipeline.handleDataRequest)
.config('server.sourceDir', process.cwd() + '/public')
.config('server.logInterval', 15)
.config('server.workerReportInterval', 5)
.config('server.port', port)
.config('server.liveReload', true)
.config('server.liveReloadPort', port + 100)
.postinit(require('./lib/init/cluster'));
};
// Export public classes
[
'Master',
'Worker'
].forEach(function (path) {
var name = path.split('/').pop();
module.exports[name] = require('./lib/' + path);
});
module.exports.start = function bootstrap (next) {
asimov
.use(module.exports)
.start(next);
};
module.parent || module.exports.start();