-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.default.js
More file actions
41 lines (35 loc) · 1.26 KB
/
server.default.js
File metadata and controls
41 lines (35 loc) · 1.26 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
require.paths.unshift(__dirname + '/lib');
var sys = require('sys'),
http = require('http'),
fs = require('fs'),
conductor = require('conductor');
//read config.json
try {
var configJSON = fs.readFileSync(__dirname + "/config.json");
var config = JSON.parse(configJSON.toString());
conductor.config = config;
} catch(e) {
console.log("File config.json not found. Try: `cp config.json.sample config.json`");
console.error(e);
}
//setup default variables
var port = (process.env.PORT || config.port); // use env var, otherwise use value from config.json
// all before functions receive a single parameter
// 1) the query string as a generic object
// return true to cancel the action
conductor.beforeCreate = null;
conductor.beforeStart = null;
conductor.beforeStop = null;
conductor.beforeTerminate = null;
conductor.beforeAssociateAddress = null;
// all after function receive three parameters
// 1) the query string as a generic object
// 2) the http return code as an int
// 3) the http return message as a string
conductor.afterCreate = null;
conductor.afterStart = null;
conductor.afterStop = null;
conductor.afterTerminate = null;
conductor.afterAssociateAddress = null;
http.createServer(conductor.router).listen(port);
console.log('Listening on http://0.0.0.0:' + port);