diff --git a/.travis.yml b/.travis.yml index f98fed0..94ab01f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,4 +2,3 @@ language: node_js node_js: - '12' - '10' - - '8' diff --git a/index.js b/index.js index 31478c4..f15fad7 100644 --- a/index.js +++ b/index.js @@ -13,10 +13,16 @@ const URL = require('url-parse'); const dnsLookupP = promisify(dns.lookup); -const checkHttp = async url => { +const checkHttp = async (url, timeout) => { let response; try { - response = await got(url, {rejectUnauthorized: false}); + response = await got(url, { + https: { + rejectUnauthorized: false + }, + retry: 0, + timeout + }); } catch (_) { return false; } @@ -32,7 +38,7 @@ const checkHttp = async url => { const getAddress = async hostname => net.isIP(hostname) ? hostname : (await dnsLookupP(hostname)).address; -const isTargetReachable = async target => { +const isTargetReachable = timeout => async target => { const url = new URL(prependHttp(target)); if (!url.port) { @@ -51,7 +57,7 @@ const isTargetReachable = async target => { } if ([80, 443].includes(url.port)) { - return checkHttp(url.toString()); + return checkHttp(url.toString(), timeout); } return isPortReachable(url.port, {host: address}); @@ -61,6 +67,6 @@ module.exports = async (destinations, options) => { options = {...options}; options.timeout = typeof options.timeout === 'number' ? options.timeout : 5000; - const promise = pAny(arrify(destinations).map(isTargetReachable)); + const promise = pAny(arrify(destinations).map(isTargetReachable(options.timeout))); return pTimeout(promise, options.timeout).catch(() => false); }; diff --git a/package.json b/package.json index b5f11be..8a52167 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "url": "sindresorhus.com" }, "engines": { - "node": ">=8" + "node": ">=10" }, "scripts": { "test": "xo && ava test.js && tsd" @@ -40,7 +40,7 @@ ], "dependencies": { "arrify": "^2.0.1", - "got": "^9.6.0", + "got": "^11.7.0", "is-port-reachable": "^2.0.1", "p-any": "^2.1.0", "p-timeout": "^3.2.0",