Commit ad442cb2f342e9c964ee3648fff629aaa2952089

Authored by Adhidarma Hadiwinoto
1 parent 5edcdba8e3
Exists in master

No SSL for ip

Showing 3 changed files with 27 additions and 1 deletions Side-by-side Diff

... ... @@ -2,7 +2,9 @@
2 2  
3 3 process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
4 4  
  5 +const URL = require('url');
5 6 const fs = require('fs');
  7 +const isIp = require('is-ip');
6 8 const config = require(__dirname + '/config.json');
7 9  
8 10 fs.existsSync('certs') || fs.mkdirSync('certs');
... ... @@ -15,11 +17,21 @@ for (let i=0; i < hostsCount; i++) {
15 17 console.log(`Registering ${host.host} to ${host.target}`);
16 18 if (!host.disable) {
17 19 const options = host.options || config.default_host_options;
  20 + const optionsWoSSL = JSON.parse(JSON.stringify(options));
  21 + delete optionsWoSSL.ssl;
  22 +
18 23 if (!options) {
19 24 redbird.register(host.host, host.target);
20 25 }
21 26 else {
22   - redbird.register(host.host, host.target, options);
  27 +
  28 + if isIp(URL.parse(host.host).hostname) {
  29 + redbird.register(host.host, host.target, optionsWoSSL);
  30 + }
  31 + else {
  32 + redbird.register(host.host, host.target, options);
  33 + }
  34 +
23 35 }
24 36  
25 37 }
... ... @@ -470,11 +470,24 @@
470 470 "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
471 471 "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
472 472 },
  473 + "ip-regex": {
  474 + "version": "2.1.0",
  475 + "resolved": "https://registry.npmjs.org/ip-regex/-/ip-regex-2.1.0.tgz",
  476 + "integrity": "sha1-+ni/XS5pE8kRzp+BnuUUa7bYROk="
  477 + },
473 478 "is": {
474 479 "version": "3.3.0",
475 480 "resolved": "https://registry.npmjs.org/is/-/is-3.3.0.tgz",
476 481 "integrity": "sha512-nW24QBoPcFGGHJGUwnfpI7Yc5CdqWNdsyHQszVE/z2pKHXzh7FZ5GWhJqSyaQ9wMkQnsTx+kAI8bHlCX4tKdbg=="
477 482 },
  483 + "is-ip": {
  484 + "version": "2.0.0",
  485 + "resolved": "https://registry.npmjs.org/is-ip/-/is-ip-2.0.0.tgz",
  486 + "integrity": "sha1-aO6gfooKCpTC0IDdZ0xzGrKkYas=",
  487 + "requires": {
  488 + "ip-regex": "^2.0.0"
  489 + }
  490 + },
478 491 "is-my-ip-valid": {
479 492 "version": "1.0.0",
480 493 "resolved": "https://registry.npmjs.org/is-my-ip-valid/-/is-my-ip-valid-1.0.0.tgz",
... ... @@ -17,6 +17,7 @@
17 17 "author": "Adhidarma Hadiwinoto <me@adhisimon.org>",
18 18 "license": "ISC",
19 19 "dependencies": {
  20 + "is-ip": "^2.0.0",
20 21 "redbird": "^0.9.0"
21 22 }
22 23 }