src/health-loader.js
function setupHealth(expressRouter, baseURI, dependenciesDef, logger) {
  if (typeof (dependenciesDef) === 'string') {
    if (!dependenciesDef.startsWith('/')) {
      dependenciesDef = `${process.cwd()}/${dependenciesDef}`;
    }
    if (!fs.existsSync(dependenciesDef)) {
      throw new Error(`Health dependencies file doesn't exists -> ${dependenciesDef}`);
    }
    if (!dependenciesDef.endsWith('.yml') || !dependenciesDef.endsWith('.yaml')) {
      throw new Error(`Health dependencies file is not a YAML file -> ${dependenciesDef}`);
    }
    dependenciesDef = jsYaml.load(fs.readFileSync(dependenciesDef));
  }
  expressRouter.get(`/${baseURI}/health`, setupHealthHandler(dependenciesDef, logger));
  logger.info(`RIK_HEALTH: Setup a Healthcheck endpoint at '/${baseURI}/health'`);
}
function setupHealth(expressRouter, baseURI, dependenciesDef, logger) {
  if (typeof (dependenciesDef) === 'string') {
    if (!dependenciesDef.startsWith('/')) {
      dependenciesDef = `${process.cwd()}/${dependenciesDef}`;
    }
    if (!fs.existsSync(dependenciesDef)) {
      throw new Error(`Health dependencies file doesn't exists -> ${dependenciesDef}`);
    }
    if (!dependenciesDef.endsWith('.yml') || !dependenciesDef.endsWith('.yaml')) {
      throw new Error(`Health dependencies file is not a YAML file -> ${dependenciesDef}`);
    }
    dependenciesDef = jsYaml.load(fs.readFileSync(dependenciesDef));
  }
  expressRouter.get(`/${baseURI}/health`, setupHealthHandler(dependenciesDef, logger));
  logger.info(`RIK_HEALTH: Setup a Healthcheck endpoint at '/${baseURI}/health'`);
}
function setupHealth ( expressRouter , baseURI , dependenciesDef , logger ) { if ( typeof ( dependenciesDef ) === 'string' ) { if ( ! dependenciesDef . startsWith ( '/' ) ) { dependenciesDef = ` ${ process . cwd ( ) } ${ dependenciesDef } ` ; } if ( ! fs . existsSync ( dependenciesDef ) ) { throw new Error ( ` ${ dependenciesDef } ` ) ; } if ( ! dependenciesDef . endsWith ( '.yml' ) || ! dependenciesDef . endsWith ( '.yaml' ) ) { throw new Error ( ` ${ dependenciesDef } ` ) ; } dependenciesDef = jsYaml . load ( fs . readFileSync ( dependenciesDef ) ) ; } expressRouter . get ( ` ${ baseURI } ` , setupHealthHandler ( dependenciesDef , logger ) ) ; logger . info ( ` ${ baseURI } ` ) ; }
Setup a healthcheck endpoint in the specified Router

@param {express.Router} expressRouter Express Router reference
@param {string} baseURI Base URI where to setup a health endpoint
@param {(any|string)} dependenciesDef dependencies to check (can be an object or a yml file name)
@param {*} logger Logger object that must implement the *info, warn and error* methods
Setup a healthcheck endpoint in the specified Router