Skip to content

Commit

Permalink
update dependencies, fix lint, require node 8
Browse files Browse the repository at this point in the history
  • Loading branch information
silverwind committed Nov 24, 2018
1 parent f2aa0b0 commit f8638da
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 27 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
@@ -1,5 +1,4 @@
language: node_js
node_js:
- '8'
- '6'
- '4'
- '10'
8 changes: 3 additions & 5 deletions browser.js
Expand Up @@ -8,11 +8,9 @@ const URL = require('url-parse');
module.exports = hosts => {
return pAny(arrify(hosts).map(url => {
return new Promise(resolve => {
url = new URL(prependHttp(url));

const hostname = url.hostname;
const protocol = url.protocol || '';
const port = url.port ? `:${url.port}` : '';
let {hostname, protocol, port} = new URL(prependHttp(url));
protocol = protocol || '';
port = port ? `:${port}` : '';

const img = new Image();
img.addEventListener('load', () => resolve(true));
Expand Down
41 changes: 26 additions & 15 deletions index.js
Expand Up @@ -12,14 +12,20 @@ const prependHttp = require('prepend-http');
const routerIps = require('router-ips');
const URL = require('url-parse');

const checkRedirection = target => {
return got(target, {rejectUnauthorized: false}).then(res => {
const url = new URL(res.headers.location || 'x://x');
return !routerIps.has(url.hostname);
}).catch(() => false);
const checkRedirection = async target => {
let res;

try {
res = await got(target, {rejectUnauthorized: false});
} catch (error) {
return false;
}

const url = new URL(res.headers.location || 'x://x');
return !routerIps.has(url.hostname);
};

function isTargetReachable(target) {
async function isTargetReachable(target) {
const url = new URL(prependHttp(target));
url.port = Number(url.port) || portNumbers.getPort(url.protocol.slice(0, -1)).port || 80;

Expand All @@ -28,17 +34,22 @@ function isTargetReachable(target) {
url.protocol = ((service && service.name) ? service.name : 'unknown') + ':';
}

return getAddress(url.hostname).then(address => {
if (!address || routerIps.has(address)) {
return false;
}
let address;
try {
address = await getAddress(url.hostname);
} catch (error) {
return false;
}

if (url.protocol === 'http:' || url.protocol === 'https:') {
return checkRedirection(url.toString());
}
if (!address || routerIps.has(address)) {
return false;
}

if (url.protocol === 'http:' || url.protocol === 'https:') {
return checkRedirection(url.toString());
}

return isPortReachable(url.port, {host: address});
}).catch(() => false);
return isPortReachable(url.port, {host: address});
}

function getAddress(hostname) {
Expand Down
10 changes: 5 additions & 5 deletions package.json
Expand Up @@ -13,7 +13,7 @@
"silverwind <me@silverwind.io> (github.com/silverwind)"
],
"engines": {
"node": ">=4"
"node": ">=8"
},
"scripts": {
"test": "xo && ava test.js"
Expand Down Expand Up @@ -42,15 +42,15 @@
],
"dependencies": {
"arrify": "^1.0.1",
"got": "^8.0.3",
"got": "^9.3.2",
"is-port-reachable": "^2.0.0",
"p-any": "^1.1.0",
"p-timeout": "^2.0.1",
"pify": "^3.0.0",
"port-numbers": "^2.0.20",
"pify": "^4.0.1",
"port-numbers": "^4.0.4",
"prepend-http": "^2.0.0",
"router-ips": "^1.0.0",
"url-parse": "^1.2.0"
"url-parse": "^1.4.4"
},
"devDependencies": {
"ava": "*",
Expand Down

1 comment on commit f8638da

@silverwind
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sindresorhus feel free to publish this as 3.0.0. I can not enable 2FA with OTP on my npm account which this repository now requires because I have a few packages where I do unattended publishes. Also, I generally think OTP is too much of a nuisance.

Please sign in to comment.