Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

url-ok

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

url-ok - npm Package Compare versions

Comparing version 0.0.8 to 0.0.9

12

lib/options.js
'use strict';
var parser = require('argv-parser'),
two_minutes_in_ms = 2 * 60 * 1000;
one_second = 1000,
two_minutes_in_ms = 2 * 60 * one_second;
module.exports = parser.parse(process.argv, {
rules: {
debug: {
type: Boolean
},
interval: {
type: Number,
value: function(interval, parsed, tool) {
return interval * 1000 || one_second;
}
},
timeout: {

@@ -9,0 +19,0 @@ type: Number,

30

lib/status.js

@@ -9,10 +9,15 @@ 'use strict';

module.exports = function(url) {
module.exports = function(url, interval) {
return new promise(function(resolve, reject) {
var parsedUrl = require('url').parse(url),
protocol = (parsedUrl.protocol === 'http:') ? http : https;
protocol = (parsedUrl.protocol === 'http:') ? http : https,
request;
parsedUrl.method = (protocol === http) ? 'HEAD' : 'GET';
interval = interval || options.parsed.interval;
var makeRequest = function() {
var request = protocol
if (options.parsed.debug) {
console.log('DEBUG: requesting', url, '(interval: ' + interval + 'ms)');
}
request = protocol
.request(parsedUrl, function(response) {

@@ -25,4 +30,2 @@ if (options.parsed.verbose) {

resolve(response.statusCode);
} else {
retry();
}

@@ -32,18 +35,21 @@ });

request.on('error', function(error) {
retry();
if (options.parsed.debug) {
console.log('DEBUG: error', url, error.toString());
}
});
request.setTimeout(500);
request.setTimeout(interval);
request.end();
};
var retry = function() {
setTimeout(function() {
makeRequest();
}, 500);
return request;
};
setInterval(function() {
request.abort();
makeRequest();
}, interval);
makeRequest();
});
};
{
"name": "url-ok",
"description": "check http or https status for number of URLs with timeout",
"version": "0.0.8",
"version": "0.0.9",
"bin": "main.js",

@@ -6,0 +6,0 @@ "main": "lib/url-ok.js",

@@ -10,9 +10,11 @@ # url-ok [![Build Status](https://travis-ci.org/cymen/url-ok.png?branch=master)](https://travis-ci.org/cymen/url-ok)

If a URL cannot be reached, it will continue to try to reach the URL every 500 milleseconds
up to the timeout. For HTTP, it uses a HEAD request while for HTTPS it uses GET.
If a URL cannot be reached, it will continue to try to reach the URL every second up to the timeout.
For HTTP, it uses a HEAD request while for HTTPS it uses GET.
## Options
--timeout to set a specific timeout in seconds
--timeout to set a specific timeout in seconds (default 120 seconds)
--interval to set a specific interval between attempts (defaults to one second)
--verbose to enable verbose output
--debug to enable extremely verbose output

@@ -36,3 +38,3 @@ ## Example of a successful run

# url-ok http://no.such.server.localhost/ --timeout 10 --verbose
# url-ok http://no.such.server.localhost/ --timeout 10 --interval 2 --verbose
Waiting up to 10 seconds for response(s).

@@ -46,4 +48,26 @@ Requesting http://no.such.server.localhost/

## Example of failing run with debugging
# url-ok http://no.such.server.localhost/ --timeout 10 --interval 2 --verbose --debug
Waiting up to 10 seconds for response(s).
Requesting http://no.such.server.localhost/
DEBUG: requesting http://no.such.server.localhost/
DEBUG: error http://no.such.server.localhost/ Error: getaddrinfo ENOTFOUND
DEBUG: requesting http://no.such.server.localhost/
DEBUG: error http://no.such.server.localhost/ Error: getaddrinfo ENOTFOUND
DEBUG: requesting http://no.such.server.localhost/
DEBUG: error http://no.such.server.localhost/ Error: getaddrinfo ENOTFOUND
DEBUG: requesting http://no.such.server.localhost/
DEBUG: error http://no.such.server.localhost/ Error: getaddrinfo ENOTFOUND
DEBUG: requesting http://no.such.server.localhost/
DEBUG: error http://no.such.server.localhost/ Error: getaddrinfo ENOTFOUND
Aborting after 10 seconds!
At least one URL failed to respond!
## Install
npm install -g url-ok
## Todo
* add timestamps to logging

@@ -13,3 +13,3 @@ 'use strict';

it('resolves successfully when all URLs are successful', function(done) {
var urls = ['http://localhost:32001/', 'http://localhost:32002'],
var urls = ['http://localhost:32001/', 'http://localhost:32002/'],
thirty_seconds_in_ms = 30 * 1000;

@@ -16,0 +16,0 @@

@@ -47,3 +47,3 @@ 'use strict';

it('keeps trying until it gets a response', function(done) {
it('keeps trying even if server is down until it gets a response', function(done) {
var url = "http://localhost:32768/";

@@ -55,5 +55,5 @@

.reply(successCode);
}, 1000);
}, 125);
var pending = status(url);
var pending = status(url, 50);

@@ -66,3 +66,3 @@ pending.done(function(code) {

it('keeps trying if it gets a non-successCode response', function(done) {
it('keeps trying if it gets a non-successCode response at first', function(done) {
var url = "http://localhost:32999/";

@@ -69,0 +69,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc