Socket
Socket
Sign inDemoInstall

is-reachable

Package Overview
Dependencies
44
Maintainers
2
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.0.0 to 5.0.0

32

index.js

@@ -16,7 +16,13 @@ 'use strict';

const checkHttp = async url => {
const checkHttp = async (url, timeout) => {
let response;
try {
response = await got(url, {rejectUnauthorized: false});
} catch (_) {
response = await got(url, {
https: {
rejectUnauthorized: false
},
retry: 0,
timeout
});
} catch {
return false;

@@ -27,3 +33,3 @@ }

const url = new URL(response.headers.location);
const hostname = url.hostname.replace(/^\[/, '').replace(/\]$/, ''); // Strip [] from IPv6
const hostname = url.hostname.replace(/^\[/, '').replace(/]$/, ''); // Strip [] from IPv6
return !routerIps.has(hostname);

@@ -37,3 +43,3 @@ }

const isTargetReachable = async target => {
const isTargetReachable = timeout => async target => {
const url = new URL(prependHttp(target));

@@ -48,3 +54,3 @@

address = await getAddress(url.hostname);
} catch (_) {
} catch {
return false;

@@ -58,3 +64,3 @@ }

if ([80, 443].includes(url.port)) {
return checkHttp(url.toString());
return checkHttp(url.toString(), timeout);
}

@@ -65,8 +71,10 @@

module.exports = async (destinations, options) => {
options = {...options};
options.timeout = typeof options.timeout === 'number' ? options.timeout : 5000;
module.exports = async (destinations, {timeout = 5000} = {}) => {
const promise = pAny(arrify(destinations).map(isTargetReachable(timeout)));
const promise = pAny(arrify(destinations).map(isTargetReachable));
return pTimeout(promise, options.timeout).catch(() => false);
try {
return await pTimeout(promise, timeout);
} catch {
return false;
}
};
{
"name": "is-reachable",
"version": "4.0.0",
"version": "5.0.0",
"description": "Check if servers are reachable",
"license": "MIT",
"repository": "sindresorhus/is-reachable",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=8"
"node": ">=10"
},

@@ -43,5 +44,5 @@ "scripts": {

"arrify": "^2.0.1",
"got": "^9.6.0",
"is-port-reachable": "^2.0.1",
"p-any": "^2.1.0",
"got": "^11.7.0",
"is-port-reachable": "^3.0.0",
"p-any": "^3.0.0",
"p-timeout": "^3.2.0",

@@ -54,6 +55,6 @@ "prepend-http": "^3.0.1",

"ava": "^2.4.0",
"tsd": "^0.8.0",
"xo": "^0.24.0"
"tsd": "^0.13.1",
"xo": "^0.34.0"
},
"browser": "browser.js"
}

@@ -1,2 +0,2 @@

# is-reachable [![Build Status](https://travis-ci.org/sindresorhus/is-reachable.svg?branch=master)](https://travis-ci.org/sindresorhus/is-reachable)
# is-reachable [![Build Status](https://travis-ci.com/sindresorhus/is-reachable.svg?branch=master)](https://travis-ci.com/github/sindresorhus/is-reachable)

@@ -11,3 +11,2 @@ > Check if servers are reachable

## Install

@@ -19,3 +18,2 @@

## Usage

@@ -35,3 +33,2 @@

## API

@@ -55,3 +52,3 @@

Type: `number`<br>
Type: `number`\
Default: `5000`

@@ -61,3 +58,2 @@

## Related

@@ -67,3 +63,2 @@

## Maintainers

@@ -70,0 +65,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc