hapi-lbstatus
Advanced tools
Comparing version
10
index.js
var service = require('./lib/provider'); | ||
exports.register = function(plugin, options, next){ | ||
plugin.route( | ||
exports.register = function(server, options, next){ | ||
server.route( | ||
{ | ||
@@ -10,3 +10,3 @@ method: "GET", | ||
handler: function(request, reply) { | ||
service.lbstatus(plugin.servers, options, function(result){ | ||
service.lbstatus(request.server, options, function(result){ | ||
reply(result.body).code(result.code); | ||
@@ -19,4 +19,4 @@ }); | ||
plugin.expose('lbstatus', function(cb){ | ||
service.lbstatus(plugin.servers, options, function(result){ | ||
server.expose('lbstatus', function(cb){ | ||
service.lbstatus(server, options, function(result){ | ||
cb(result.code === 200); | ||
@@ -23,0 +23,0 @@ }); |
var fs = require("fs"), | ||
async = require("async"), | ||
@@ -33,3 +32,3 @@ getStatus = function(applicationStatus, dependenciesStatusCode){ | ||
lbstatus = function(servers, config, callback){ | ||
lbstatus = function(server, config, callback){ | ||
var on = config.on || "ON"; | ||
@@ -39,12 +38,7 @@ var off = config.off || "ON"; | ||
async.forEach(servers, function(server, done){ | ||
applicationOffLine(server, config.file, function(file){ | ||
checkDependencies(server, config.liveness, config.headers, function(statusCode){ | ||
results.push(getStatus(file, statusCode)); | ||
done(); | ||
}); | ||
applicationOffLine(server, config.file, function(file){ | ||
checkDependencies(server, config.liveness, config.headers, function(statusCode){ | ||
var success = getStatus(file, statusCode); | ||
callback({ body: success ? on : off, code: success ? 200 : 503}); | ||
}); | ||
}, function(){ | ||
var failed = results.filter(function(i){ return i === false; }).length > 0; | ||
callback({ body: failed ? off : on, code: failed ? 503 : 200}); | ||
}); | ||
@@ -51,0 +45,0 @@ }; |
{ | ||
"name": "hapi-lbstatus", | ||
"version": "2.1.2", | ||
"version": "3.0.0", | ||
"description": "lbstatus plugin for hapi", | ||
@@ -31,5 +31,6 @@ "main": "index.js", | ||
}, | ||
"dependencies": { | ||
"async": "^0.9.0" | ||
"dependencies": {}, | ||
"peerDependencies": { | ||
"hapi": "^8.0.0" | ||
} | ||
} |
describe('lbstatus tests', function(){ | ||
var should = require('should'), | ||
provider = require('../lib/provider'), | ||
servers = [{ | ||
server = { | ||
inject: function(options, callback){ | ||
@@ -9,4 +9,4 @@ callback({ statusCode: 200 }); | ||
log: function(){} | ||
}], | ||
badservers = [{ | ||
}, | ||
badserver = { | ||
inject: function(options, callback){ | ||
@@ -16,3 +16,3 @@ callback({ statusCode: 500 }); | ||
log: function(){} | ||
}]; | ||
}; | ||
@@ -50,3 +50,3 @@ it('should register the route', function(){ | ||
it('should read the file', function(done){ | ||
provider.lbstatus(servers, { | ||
provider.lbstatus(server, { | ||
file: __dirname + '/statusfile-on', | ||
@@ -64,3 +64,3 @@ liveness: '/my/app/123', | ||
it('should return off when the file says off', function(done){ | ||
provider.lbstatus(servers, { | ||
provider.lbstatus(server, { | ||
file: __dirname + '/statusfile-off', | ||
@@ -78,3 +78,3 @@ liveness: '/my/app/123', | ||
it('should return off when the file is missing', function(done){ | ||
provider.lbstatus(servers, { | ||
provider.lbstatus(server, { | ||
file: __dirname + '/statusfile-missing', | ||
@@ -92,3 +92,3 @@ liveness: '/my/app/123', | ||
it('should use the config value for returning the string', function(done){ | ||
provider.lbstatus(servers, { | ||
provider.lbstatus(server, { | ||
file: __dirname + '/statusfile-on', | ||
@@ -106,3 +106,3 @@ liveness: '/my/app/123', | ||
it('should return off when the liveness check fails', function(done){ | ||
provider.lbstatus(badservers, { | ||
provider.lbstatus(badserver, { | ||
file: __dirname + '/statusfile-on', | ||
@@ -109,0 +109,0 @@ liveness: '/my/app/123', |
9966
-2.4%194
-3%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed