forked from ripple/ripple-rest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
47 lines (39 loc) · 1.26 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
var fs = require('fs');
var https = require('https');
var path = require('path');
var app = require(__dirname+'/lib/express_app.js');
var config = require(__dirname+'/lib/config-loader');
var remote = require(__dirname+'/lib/remote.js');
var port = config.get('port') || 5990;
var host = config.get('host');
function loadSSLConfig() {
var keyPath = config.get('ssl').key_path
|| path.join(__dirname, '/certs/server.key');
var certPath = config.get('ssl').cert_path
|| path.join(__dirname, '/certs/server.crt');
if (!fs.existsSync(keyPath)) {
console.error('Must specify key_path in order to use SSL');
process.exit(1);
}
if (!fs.existsSync(certPath)) {
console.error('Must specify cert_path in order to use SSL');
process.exit(1);
}
return {
key: fs.readFileSync(keyPath),
cert: fs.readFileSync(certPath)
};
};
if (config.get('ssl_enabled')) {
require('https').createServer(loadSSLConfig(), app).listen(port, host, function() {
console.log('ripple-rest server listening over HTTPS at port:', port);
});
} else {
app.listen(port, host, function() {
console.log('ripple-rest server listening over UNSECURED HTTP at port:', port);
});
}
// Connect to Ripple
if (!process.env.TRAVIS) {
app.remote.connect();
}