@forrestjs/service-fastify-healthz

    4.0.0 • Public • Published

    @forrestjs/service-fastify-healthz

    ForrestJS service which helps setting up an Fastify healthcheck route.

    DEMO:
    https://codesandbox.io/s/service-fastify-healthz-4g3my

    Install & Setup

    npm install --save @forrestjs/hooks @forrestjs/service-fastify @forrestjs/service-fastify-healthz

    set it up in your FastifyJS App:

    // index.js
    const { runHookApp } = require('@forrestjs/hooks');
    const fastifyService = require('@forrestjs/service-fastify');
    const fastifyHealthzService = require('@forrestjs/service-fastify-healthz');
    
    // Create a custom healthcheck response
    const HEALTHZ_MSG = 'This is a custom healthcheck response';
    const customHealthz = ({ registerHandler }) =>
      registerHandler(async () => HEALTHZ_MSG);
    
    // Run the app:
    runHookApp({
      services: [fastifyService, fastifyHealthzService],
    });

    Configuration & ENVs

    fastify.healthz.method

    default: GET

    fastify.healthz.url

    default: /healthz

    Hooks

    FASTIFY_HEALTHZ_HANDLER

    This hooks allows to override the default healthcheck route.
    It is useful in case you want to perform rich logic during a healthcheck.

    // Create a custom healthcheck response
    const HEALTHZ_MSG = 'This is a custom healthcheck response';
    const customHealthz = ({ registerHandler }) =>
      registerHandler(async () => HEALTHZ_MSG);
    
    runHookApp({
      /* other stuff... */
      features: [['$FASTIFY_HEALTHZ_HANDLER', customHealthz]],
    });

    Install

    npm i @forrestjs/service-fastify-healthz

    DownloadsWeekly Downloads

    373

    Version

    4.0.0

    License

    MIT

    Unpacked Size

    5.56 kB

    Total Files

    5

    Last publish

    Collaborators

    • marcopeg