-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·53 lines (42 loc) · 1.16 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
50
51
52
53
/**
* Module dependencies.
*/
var app = module.exports = require('lib/boot');
var http = require('http');
var https = require('https');
var balance = require('lib/balance');
var config = require('lib/config');
var fs = require('fs');
var log = require('debug')('democracyos:root');
var secure = 'https' == config('protocol');
/**
* Configure standard server
*/
var server = http.createServer(app);
var port = config('privatePort');
/**
* Configure secure server (SSL) if necessary
*/
var secureServer;
var securePort;
if (secure) {
var ssl = config('ssl');
var privateKey = fs.readFileSync(ssl.serverKey, 'utf-8');
var certificate = fs.readFileSync(ssl.serverCert, 'utf-8');
secureServer = https.createServer({ key: privateKey, cert: certificate }, app);
securePort = ssl.port;
}
var launch = function launchServer () {
server.listen(port, function() {
log('Application started on port %d', port);
});
if (secureServer && securePort) {
secureServer.listen(securePort, function() {
log('Secure application started on port %d', securePort);
});
}
};
/**
* Launch the server!
*/
if (module === require.main) launch();