index.js
1.18 KB
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
"use strict";
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
const fs = require('fs');
const isIp = require('is-ip');
// const config = require(__dirname + '/config.json');
const config = require('./config');
fs.existsSync('certs') || fs.mkdirSync('certs');
const redbird = require('redbird')(config.server_options);
const hostsCount = config.hosts.length;
for (let i=0; i < hostsCount; i++) {
let host = config.hosts[i]
console.log(`Registering ${host.host} to ${host.target}`);
if (!host.disable) {
const options = host.options || config.default_host_options;
const optionsWoSSL = JSON.parse(JSON.stringify(options));
delete optionsWoSSL.ssl;
if (!options) {
redbird.register(host.host, host.target);
}
else {
if (host.no_ssl || isIp(host.host.split('/')[0])) {
console.log('Register ' + host.host + ' without SSL')
redbird.register(host.host, host.target, optionsWoSSL);
}
else {
console.log('Register ' + host.host + ' with SSL if exists');
redbird.register(host.host, host.target, options);
}
}
}
}