-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathserver.js
61 lines (51 loc) · 1.86 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var fs = require('fs');
var https = require('https');
var constants = require('constants')
var app = require('./lib/express_app.js');
var config = require('./lib/config');
var logger = require('./lib/logger.js').logger;
var utils = require('./lib/utils.js');
var port = config.get('port') || 5990;
var host = config.get('host');
logger.info('radr-rest (v' + utils.getPackageVersion() + ')');
function loadSSLConfig() {
var keyPath = config.get('ssl').key_path || './certs/server.key';
var certPath = config.get('ssl').cert_path || './certs/server.crt';
if (!fs.existsSync(keyPath)) {
logger.error('Must specify key_path in order to use SSL');
process.exit(1);
}
if (!fs.existsSync(certPath)) {
logger.error('Must specify cert_path in order to use SSL');
process.exit(1);
}
return {
key: fs.readFileSync(keyPath),
cert: fs.readFileSync(certPath),
//
// Protecting against POODLE in node.js
// source: https://gist.github.com/3rd-Eden/715522f6950044da45d8
//
//
// This is the default secureProtocol used by Node.js, but it might be
// sane to specify this by default as it's required if you want to
// remove supported protocols from the list. This protocol supports:
//
// - SSLv2, SSLv3, TLSv1, TLSv1.1 and TLSv1.2
//
secureProtocol: 'SSLv23_method',
//
// Supply `SSL_OP_NO_SSLv3` constant as secureOption to disable SSLv3
// from the list of supported protocols that SSLv23_method supports.
secureOptions: constants.SSL_OP_NO_SSLv3
};
};
if (config.get('ssl_enabled')) {
require('https').createServer(loadSSLConfig(), app).listen(port, host, function() {
logger.info('server listening over HTTPS at port ' + port);
});
} else {
app.listen(port, host, function() {
logger.info('server listening over UNSECURED HTTP at port ' + port);
});
}