Commit 67c0d1117898997e044bdf04b8b95e4b498ae8aa

Authored by Adhidarma Hadiwinoto
1 parent ae51086d23
Exists in master

Perbaikan deteksi ip

Showing 1 changed file with 1 additions and 2 deletions Inline Diff

1 "use strict"; 1 "use strict";
2 2
3 process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; 3 process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
4 4
5 const URL = require('url');
6 const fs = require('fs'); 5 const fs = require('fs');
7 const isIp = require('is-ip'); 6 const isIp = require('is-ip');
8 const config = require(__dirname + '/config.json'); 7 const config = require(__dirname + '/config.json');
9 8
10 fs.existsSync('certs') || fs.mkdirSync('certs'); 9 fs.existsSync('certs') || fs.mkdirSync('certs');
11 10
12 const redbird = require('redbird')(config.server_options); 11 const redbird = require('redbird')(config.server_options);
13 12
14 const hostsCount = config.hosts.length; 13 const hostsCount = config.hosts.length;
15 for (let i=0; i < hostsCount; i++) { 14 for (let i=0; i < hostsCount; i++) {
16 let host = config.hosts[i] 15 let host = config.hosts[i]
17 console.log(`Registering ${host.host} to ${host.target}`); 16 console.log(`Registering ${host.host} to ${host.target}`);
18 if (!host.disable) { 17 if (!host.disable) {
19 const options = host.options || config.default_host_options; 18 const options = host.options || config.default_host_options;
20 const optionsWoSSL = JSON.parse(JSON.stringify(options)); 19 const optionsWoSSL = JSON.parse(JSON.stringify(options));
21 delete optionsWoSSL.ssl; 20 delete optionsWoSSL.ssl;
22 21
23 if (!options) { 22 if (!options) {
24 redbird.register(host.host, host.target); 23 redbird.register(host.host, host.target);
25 } 24 }
26 else { 25 else {
27 26
28 if (isIp(URL.parse(host.host).hostname)) { 27 if (isIp(host.host.split('/')[0])) {
29 console.log('Register ' + host.host + ' without SSL') 28 console.log('Register ' + host.host + ' without SSL')
30 redbird.register(host.host, host.target, optionsWoSSL); 29 redbird.register(host.host, host.target, optionsWoSSL);
31 } 30 }
32 else { 31 else {
33 console.log('Register ' + host.host + ' with SSL if exists'); 32 console.log('Register ' + host.host + ' with SSL if exists');
34 redbird.register(host.host, host.target, options); 33 redbird.register(host.host, host.target, options);
35 } 34 }
36 35
37 } 36 }
38 37
39 } 38 }
40 } 39 }
41 40