-
Notifications
You must be signed in to change notification settings - Fork 486
/
server.js
41 lines (37 loc) · 1.15 KB
/
server.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
/*global console*/
var yetify = require('yetify'),
config = require('getconfig'),
fs = require('fs'),
sockets = require('./sockets'),
port = parseInt(process.env.PORT || config.server.port, 10),
server_handler = function (req, res) {
if (req.url === '/healthcheck') {
console.log(Date.now(), 'healthcheck');
res.writeHead(200);
res.end();
return;
}
res.writeHead(404);
res.end();
},
server = null;
// Create an http(s) server instance to that socket.io can listen to
if (config.server.secure) {
server = require('https').Server({
key: fs.readFileSync(config.server.key),
cert: fs.readFileSync(config.server.cert),
passphrase: config.server.password
}, server_handler);
} else {
server = require('http').Server(server_handler);
}
server.listen(port);
sockets(server, config);
if (config.uid) process.setuid(config.uid);
var httpUrl;
if (config.server.secure) {
httpUrl = "https://localhost:" + port;
} else {
httpUrl = "http://localhost:" + port;
}
console.log(yetify.logo() + ' -- signal master is running at: ' + httpUrl);