{"version":3,"sources":["jsdelivr-header.js","/npm/topcoder-healthcheck-dropin@1.0.3/dist/index.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,ACNA,aAEA,IAAI,SAAW,QAAQ,WAEnB,UAAY,uBAAuB,UAEvC,SAAS,uBAAuB,GAAO,OAAO,GAAO,EAAI,WAAa,EAAM,CAAE,QAAS,EAAO,CAK9F,IAAI,aAAe,IAKf,YAAc,IAelB,SAAS,oBAAoB,EAAK,EAAK,GACrC,OAAI,GACK,EAAO,QAAO,SAAU,EAAa,GAC1C,OAAO,GAAe,EAAM,EAAK,EACnC,IAAG,EAGP,CAUA,SAAS,YAAY,EAAK,EAAK,GAC7B,IAAI,EAAS,oBAAoB,EAAK,EAAK,GAE3C,OADA,EAAI,OAAO,EAAS,aAAe,aAAa,KAAK,CAAE,UAAW,EAAS,EAAO,OAAS,IACpF,CACT,CAQA,SAAS,WAAW,GAClB,OAAO,SAAgB,EAAK,EAAK,GACf,YAAZ,EAAI,IACN,YAAY,EAAK,EAAK,GAEtB,GAEJ,CACF,CASA,SAAS,KAAK,EAAQ,GACpB,IAAI,EAAc,EACd,EAAa,EACK,mBAAX,IACT,EAAc,KACd,EAAa,GAGV,IACH,EAAa,SAAoB,GAC1B,EAGH,QAAQ,IAAI,GAFZ,QAAQ,IAAI,yDAIhB,GAGF,IAAI,GAAM,EAAI,UAAU,WACxB,EAAI,IAAI,UAAW,WAAW,IAC9B,IAAI,EAAO,QAAQ,IAAI,MAAQ,IAC/B,OAAO,EAAI,OAAO,GAAM,SAAU,GAChC,QAAQ,IAAI,6DAA+D,GAC3E,EAAW,EACb,GACF,CAEA,OAAO,QAAU,CACf,KAAM,KACN,WAAY,WACZ,aAAc,aACd,YAAa","file":"/npm/topcoder-healthcheck-dropin@1.0.3/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/topcoder-healthcheck-dropin@1.0.3/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict';\n\nvar _express = require('express');\n\nvar _express2 = _interopRequireDefault(_express);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\n/** @constant HTTP_HEALTHY\n    @type {integer}\n*/\nvar HTTP_HEALTHY = 200;\n\n/** @constant HTTP_FAILED\n    @type {integer}\n*/\nvar HTTP_FAILED = 503;\n\n/**\n * executeCustomChecks - executes custom check functions\n *\n */\n\n/**\n  * executeCustomChecks - description\n  *\n  * @param  {object} req    request object\n  * @param  {object} res    response object\n  * @param  {array} checks array of functions to execute to check service health. functions must return boolean\n  * @returns {boolean}        Returns true if checks is falsy otherwise returns false if any check fails\n  */\nfunction executeCustomChecks(req, res, checks) {\n  if (checks) {\n    return checks.reduce(function (accumulator, check) {\n      return accumulator && check(req, res);\n    }, true);\n  }\n  return true;\n}\n\n/**\n * healthCheck - health check function to be used in middleware\n *\n * @param  {object} req    request object\n * @param  {object} res    response object\n * @param  {array} checks array of functions to execute health check\n * @returns {boolean}        result of checks\n */\nfunction healthCheck(req, res, checks) {\n  var result = executeCustomChecks(req, res, checks);\n  res.status(result ? HTTP_HEALTHY : HTTP_FAILED).json({ checksRun: checks ? checks.length : 0 });\n  return result;\n}\n\n/**\n * middleware - express middleware for executing custom health checks\n *\n * @param  {array} checks optional array of functions to execute to check service health. functions must return boolean\n * @returns {function}        middleware function\n */\nfunction middleware(checks) {\n  return function middle(req, res, next) {\n    if (req.url === '/health') {\n      healthCheck(req, res, checks);\n    } else {\n      next();\n    }\n  };\n}\n\n/**\n  * init - intialize an express server for running a default `/health` endpoint\n  *\n  * @param  {array} checks optional array of functions to execute to check service health. functions must return boolean\n  * @param  {type} cb     optional callback to execute once the server is started\n  * @returns {object}        returns the express server that was initialized\n  */\nfunction init(checks, cb) {\n  var checksArray = checks;\n  var svcStartCB = cb;\n  if (typeof checks === 'function') {\n    checksArray = null;\n    svcStartCB = checks;\n  }\n\n  if (!svcStartCB) {\n    svcStartCB = function svcStartCB(err) {\n      if (!err) {\n        console.log('Topcoder Health Check DropIn started and ready to roll');\n      } else {\n        console.log(err);\n      }\n    };\n  }\n\n  var app = (0, _express2.default)();\n  app.get('/health', middleware(checksArray));\n  var port = process.env.PORT || 3000;\n  return app.listen(port, function (err) {\n    console.log('********** Topcoder Health Check DropIn listening on port ' + port);\n    svcStartCB(err);\n  });\n}\n\nmodule.exports = {\n  init: init,\n  middleware: middleware,\n  HTTP_HEALTHY: HTTP_HEALTHY,\n  HTTP_FAILED: HTTP_FAILED\n};"]}