diff --git a/lib/index.js b/lib/index.js index 8f0041b..b936284 100644 --- a/lib/index.js +++ b/lib/index.js @@ -7,7 +7,7 @@ if (options == null) { options = {}; } - routes(plugin); + routes(plugin, options); if (process.env.NODE_ENV === 'test') { plugin.expose('dummy', {}); } diff --git a/lib/index.js.map b/lib/index.js.map index 2fcbdbd..77127b5 100644 --- a/lib/index.js.map +++ b/lib/index.js.map @@ -6,5 +6,5 @@ "index.coffee" ], "names": [], - "mappings": "AAAA;AAAA,MAAA,MAAA;;AAAA,EAAA,MAAA,GAAS,OAAA,CAAQ,UAAR,CAAT,CAAA;;AAAA,EAEA,MAAM,CAAC,OAAO,CAAC,QAAf,GAA0B,SAAC,MAAD,EAAS,OAAT,EAAuB,EAAvB,GAAA;;MAAS,UAAU;KAC3C;AAAA,IAAA,MAAA,CAAO,MAAP,CAAA,CAAA;AAEA,IAAA,IAA6B,OAAO,CAAC,GAAG,CAAC,QAAZ,KAAwB,MAArD;AAAA,MAAA,MAAM,CAAC,MAAP,CAAc,OAAd,EAAuB,EAAvB,CAAA,CAAA;KAFA;WAIA,EAAA,CAAA,EALwB;EAAA,CAF1B,CAAA;;AAAA,EASA,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,UAAxB,GACE;AAAA,IAAA,GAAA,EAAK,OAAA,CAAQ,iBAAR,CAAL;GAVF,CAAA;AAAA" + "mappings": "AAAA;AAAA,MAAA,MAAA;;AAAA,EAAA,MAAA,GAAS,OAAA,CAAQ,UAAR,CAAT,CAAA;;AAAA,EAEA,MAAM,CAAC,OAAO,CAAC,QAAf,GAA0B,SAAC,MAAD,EAAS,OAAT,EAAuB,EAAvB,GAAA;;MAAS,UAAU;KAC3C;AAAA,IAAA,MAAA,CAAO,MAAP,EAAe,OAAf,CAAA,CAAA;AAEA,IAAA,IAA6B,OAAO,CAAC,GAAG,CAAC,QAAZ,KAAwB,MAArD;AAAA,MAAA,MAAM,CAAC,MAAP,CAAc,OAAd,EAAuB,EAAvB,CAAA,CAAA;KAFA;WAIA,EAAA,CAAA,EALwB;EAAA,CAF1B,CAAA;;AAAA,EASA,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,UAAxB,GACE;AAAA,IAAA,GAAA,EAAK,OAAA,CAAQ,iBAAR,CAAL;GAVF,CAAA;AAAA" } \ No newline at end of file diff --git a/lib/routes.js b/lib/routes.js index 2af2942..837ffd2 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -1,19 +1,28 @@ (function() { - module.exports = function(plugin) { + module.exports = function(plugin, options) { return plugin.route({ - path: '/status', + path: options.path || '/status', method: 'GET', config: { auth: false }, handler: function(request, reply) { - return reply({ - running: true, - uptime: process.uptime(), - memoryUsage: process.memoryUsage(), - versions: process.versions, - droneId: process.pid - }); + if (request.info.host === options.localhost) { + return reply({ + app: options.app, + running: true, + uptime: process.uptime(), + memoryUsage: process.memoryUsage(), + versions: process.versions, + droneId: process.pid + }); + } else { + return reply({ + app: options.app, + running: true, + uptime: process.uptime() + }); + } } }); }; diff --git a/lib/routes.js.map b/lib/routes.js.map index c9f4f0a..abe56b1 100644 --- a/lib/routes.js.map +++ b/lib/routes.js.map @@ -6,5 +6,5 @@ "routes.coffee" ], "names": [], - "mappings": "AACA;AAAA,EAAA,MAAM,CAAC,OAAP,GAAiB,SAAC,MAAD,GAAA;WACf,MAAM,CAAC,KAAP,CACE;AAAA,MAAA,IAAA,EAAM,SAAN;AAAA,MACA,MAAA,EAAQ,KADR;AAAA,MAEA,MAAA,EACE;AAAA,QAAA,IAAA,EAAM,KAAN;OAHF;AAAA,MAIA,OAAA,EAAS,SAAC,OAAD,EAAU,KAAV,GAAA;eACP,KAAA,CACE;AAAA,UAAA,OAAA,EAAS,IAAT;AAAA,UACA,MAAA,EAAQ,OAAO,CAAC,MAAR,CAAA,CADR;AAAA,UAEA,WAAA,EAAa,OAAO,CAAC,WAAR,CAAA,CAFb;AAAA,UAGA,QAAA,EAAU,OAAO,CAAC,QAHlB;AAAA,UAIA,OAAA,EAAS,OAAO,CAAC,GAJjB;SADF,EADO;MAAA,CAJT;KADF,EADe;EAAA,CAAjB,CAAA;AAAA" + "mappings": "AACA;AAAA,EAAA,MAAM,CAAC,OAAP,GAAiB,SAAC,MAAD,EAAS,OAAT,GAAA;WACf,MAAM,CAAC,KAAP,CACE;AAAA,MAAA,IAAA,EAAM,OAAO,CAAC,IAAR,IAAgB,SAAtB;AAAA,MACA,MAAA,EAAQ,KADR;AAAA,MAEA,MAAA,EACE;AAAA,QAAA,IAAA,EAAM,KAAN;OAHF;AAAA,MAIA,OAAA,EAAS,SAAC,OAAD,EAAU,KAAV,GAAA;AAEP,QAAA,IAAG,OAAO,CAAC,IAAI,CAAC,IAAb,KAAqB,OAAO,CAAC,SAAhC;iBACE,KAAA,CACE;AAAA,YAAA,GAAA,EAAK,OAAO,CAAC,GAAb;AAAA,YACA,OAAA,EAAS,IADT;AAAA,YAEA,MAAA,EAAQ,OAAO,CAAC,MAAR,CAAA,CAFR;AAAA,YAGA,WAAA,EAAa,OAAO,CAAC,WAAR,CAAA,CAHb;AAAA,YAIA,QAAA,EAAU,OAAO,CAAC,QAJlB;AAAA,YAKA,OAAA,EAAS,OAAO,CAAC,GALjB;WADF,EADF;SAAA,MAAA;iBASE,KAAA,CACE;AAAA,YAAA,GAAA,EAAK,OAAO,CAAC,GAAb;AAAA,YACA,OAAA,EAAS,IADT;AAAA,YAEA,MAAA,EAAQ,OAAO,CAAC,MAAR,CAAA,CAFR;WADF,EATF;SAFO;MAAA,CAJT;KADF,EADe;EAAA,CAAjB,CAAA;AAAA" } \ No newline at end of file diff --git a/src/index.coffee b/src/index.coffee index 0babfbf..734e5b2 100644 --- a/src/index.coffee +++ b/src/index.coffee @@ -1,7 +1,7 @@ routes = require './routes' module.exports.register = (plugin, options = {}, cb) -> - routes plugin + routes plugin, options plugin.expose 'dummy', {} if process.env.NODE_ENV is 'test' diff --git a/src/routes.coffee b/src/routes.coffee index 7c6f83a..c2129ac 100644 --- a/src/routes.coffee +++ b/src/routes.coffee @@ -1,16 +1,23 @@ -module.exports = (plugin) -> +module.exports = (plugin, options) -> plugin.route - path: '/status' + path: options.path || '/status' method: 'GET' config: auth: false handler: (request, reply) -> - reply - running: true - uptime: process.uptime() - memoryUsage: process.memoryUsage() - versions: process.versions - droneId: process.pid + if request.info.host is options.localhost + reply + app: options.app + running: true + uptime: process.uptime() + memoryUsage: process.memoryUsage() + versions: process.versions + droneId: process.pid + else + reply + app: options.app + running: true + uptime: process.uptime() diff --git a/test/routes-tests.coffee b/test/routes-tests.coffee index bf9028a..b1e6bfa 100644 --- a/test/routes-tests.coffee +++ b/test/routes-tests.coffee @@ -2,6 +2,7 @@ assert = require 'assert' should = require 'should' loadServer = require './support/load-server' +loadServerWithOptions = require './support/load-server-with-config.coffee' describe 'WHEN route testing for status-routes', -> describe '/status', -> @@ -18,8 +19,38 @@ describe 'WHEN route testing for status-routes', -> response.statusCode.should.equal 200 should.exist result + result.should.have.property 'running',true + result.should.have.property 'uptime' + result.should.not.have.property 'memoryUsage' + result.should.not.have.property 'droneId' + + cb null + +describe 'WHEN route testing for "/stats" route', -> + describe '/stats', -> + loadServerWithOptions (err,server) -> + return cb err if err + it 'should respond with an up stats', (cb) -> + options = + method: "GET" + url: "/stats" + headers: + "Host" : "localhost" + + server.inject options, (response) -> + result = response.result + #console.log result + + response.statusCode.should.equal 200 + should.exist result + result.should.have.property 'running',true result.should.have.property 'uptime' result.should.have.property 'memoryUsage' - + result.should.have.property 'versions' + result.should.have.property 'droneId' + result.should.have.property 'app' + result.app.should.have.property 'name', 'myApp' + result.app.should.have.property 'version', '0.0.1-7' + cb null diff --git a/test/support/load-server-with-config.coffee b/test/support/load-server-with-config.coffee new file mode 100644 index 0000000..c44e735 --- /dev/null +++ b/test/support/load-server-with-config.coffee @@ -0,0 +1,20 @@ +index = require '../../lib/index' +Hapi = require "hapi" +_ = require 'underscore' + +# server with custom config +module.exports = loadServerWithOptions = (cb) -> + server = new Hapi.Server 5675,"localhost",{} + + pluginConf = [ + plugin: index, + options: + app: + name: "myApp" + version: "0.0.1-7" + path: '/stats' + localhost: 'localhost' + ] + + server.pack.register pluginConf, (err) -> + cb err,server \ No newline at end of file