diff --git a/lib/client/index.js b/lib/client/index.js index e4fd5e4bf..4b4e18832 100644 --- a/lib/client/index.js +++ b/lib/client/index.js @@ -16,7 +16,7 @@ module.exports = ({ port = null, config = {}, filters = {} }) => { const { app, server } = require('../webserver')(config, port); // IMPORTANT: defined before relay (`app.all('/*', ...`) - app.get('/healthcheck', (req, res, next) => { + app.get(config.brokerHealthcheckPath || '/healthcheck', (req, res) => { return res.status(200).json({ ok: true }); }); @@ -30,7 +30,7 @@ module.exports = ({ port = null, config = {}, filters = {} }) => { close: done => { logger.info('closing'); server.close(); - io.destroy(done || (() => debug('closed'))); + io.destroy(done || (() => logger.info('closed'))); }, }; }; diff --git a/test/functional/healthcheck.test.js b/test/functional/healthcheck.test.js index ee57de23f..26e8fd485 100644 --- a/test/functional/healthcheck.test.js +++ b/test/functional/healthcheck.test.js @@ -31,12 +31,16 @@ test('proxy requests originating from behind the broker client', t => { const clientPort = port(); let client = app.main({ port: clientPort }); - t.plan(6); + t.plan(7); const serverHealth = `http://localhost:${serverPort}/healthcheck`; const connectionStatus = `http://localhost:${serverPort}/` + `connection-status/${BROKER_TOKEN}`; const clientHealth = `http://localhost:${clientPort}/healthcheck`; + + // instantiated and connected later + let customHealthClient; + t.test('server healthcheck', t => { request({url: serverHealth, json: true }, (err, res) => { if (err) { return t.threw(err); } @@ -95,7 +99,33 @@ test('proxy requests originating from behind the broker client', t => { }, 20); }); + t.test('custom healthcheck endpoint', t => { + // launch second client to test custom client healthcheck + process.env.BROKER_HEALTHCHECK_PATH = '/custom/healthcheck/endpoint'; + const customClientPort = port(); + const customClientHealth = + `http://localhost:${customClientPort}/custom/healthcheck/endpoint`; + + customHealthClient = app.main({ port: customClientPort }); + + server.io.once('connection', socket => { + socket.once('identify', () => { + t.test('client custom healthcheck', t => { + request({url: customClientHealth, json: true }, (err, res) => { + if (err) { return t.threw(err); } + + t.equal(res.statusCode, 200, '200 statusCode'); + t.equal(res.body['ok'], true, '{ ok: true } in body'); + t.end(); + }); + }); + t.end(); + }); + }); + }); + t.test('clean up', t => { + customHealthClient.close(); client.close(); setTimeout(() => { server.close();