superagent-failover
v0.1.2
Published
superagent failover plugin
Downloads
1
Readme
superagent-failover
Appends a .failover
method to make trying other URLs when the main URL failed. The list of URLs will be provided through parameters of method .failover
together with the timeout that the superagent request should wait to retry.
Install
$ npm install --save superagent-failover
Usage
failover() function call with one host address (IP or domain name with port) as parameter:
var superagent = require('superagent');
require('superagent-failover')(superagent);
superagent
.get('https://down.yourdomain.com/path/to/page')
.accept('application/json')
.failover('backup.yourdomain.com')
.end(function (err, res) {
console.log('Response status: ', res.status)
console.log('... and body: ', JSON.stringify(res.body, null, 2));
});
failover() function call with one host address and timeout as parameters:
var superagent = require('superagent');
require('superagent-failover')(superagent);
superagent
.get('https://down.yourdomain.com/path/to/page')
.accept('application/json')
.failover({
url: 'backup.yourdomain.com',
timeout: 3000
})
.end(function (err, res) {
console.log('Response status: ', res.status)
console.log('... and body: ', JSON.stringify(res.body, null, 2));
});
failover() function call with a list of host addresses as parameter:
var superagent = require('superagent');
require('superagent-failover')(superagent);
superagent
.get('https://down.yourdomain.com/path/to/page')
.accept('application/json')
.failover([
'backup.yourdomain.com',
'bak.yourdomain.com:81',
'bak.yourdomain.com:82',
])
.end(function (err, res) {
console.log('Response status: ', res.status)
console.log('... and body: ', JSON.stringify(res.body, null, 2));
});
failover() function call with a list of host addresses as parameter, some urls can have its own timeout (default timeout is 2000ms):
var superagent = require('superagent');
require('superagent-failover')(superagent);
superagent
.get('https://down.yourdomain.com/path/to/page')
.accept('application/json')
.failover([
{
url: 'backup.yourdomain.com',
timeout: 3000
},
'bak.yourdomain.com:81',
'bak.yourdomain.com:82',
])
.end(function (err, res) {
console.log('Response status: ', res.status)
console.log('... and body: ', JSON.stringify(res.body, null, 2));
});