forked from ripple/ripple-rest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
47 lines (40 loc) · 1.46 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');
require('rconsole');
console.set({
facility: 'local7',
title: 'ripple-rest-server',
stdout: false,
stderr: true,
syslog: true,
syslogHashtags: false,
showTime: true,
showLine: false,
showFile: true,
showTags: true
});
/* Configure SSL, if desired */
if (typeof config.get('ssl') === 'object') {
var key_path = config.get('ssl').key_path || path.join(__dirname, '/certs/server.key');
var cert_path = config.get('ssl').cert_path || path.join(__dirname, '/certs/server.crt');
if (!fs.existsSync(key_path)) {
throw new Error('Must provide key file and a key_path in the config.json in order to use SSL');
}
if (!fs.existsSync(cert_path)) {
throw new Error('Must provide certificate file and a cert_path in the config.json in order to use SSL');
}
var sslOptions = {
key: fs.readFileSync(key_path),
cert: fs.readFileSync(cert_path)
};
https.createServer(sslOptions, app).listen(config.get('PORT'), function() {
console.log('ripple-rest server listening over HTTPS at port:', config.get('PORT'));
});
} else {
app.listen(config.get('PORT'), function() {
console.log('ripple-rest server listening over UNSECURED HTTP at port:', config.get('PORT'));
});
}