3.0.0 • Published 1 year ago

fastify-ready-checks v3.0.0

Weekly downloads
45
License
ISC
Repository
github
Last release
1 year ago

Fastify Ready Checks

Ready checks plugin for fastify Node.js web app framework

Usage

Basic usage

import fastify from 'fastify';
import plugin from 'fastify-ready-checks';
const app = fastify();
app.register(plugin);

An endpoint /live which will respond with 200 Server live will be added to your app An endpoint /ready which will respond with 500 Server not ready will be added to your app

Setting fixed boolean responses

app.register(plugin, { live: true, ready: true });

An endpoint /live which will respond with 200 Server live will be added to your app An endpoint /ready which will respond with 200 Server ready will be added to your app

Passing functions

app.register(plugin, { live: () => true, ready: () => true });

An endpoint /live will be added to your app which will first call the given live function and then respond with 200 Server live since return value of the function is truthy An endpoint /ready will be added to your app which will first call the given ready function and then respond with 200 Server ready since return value of the function is truthy

Passing functions that return promises

app.register(plugin, {
    live: () => Promise.resolve(),
    ready: () => Promise.reject(),
});

An endpoint /live will be added to your app which will first call the given live function, then await the returned promise and then respond with 200 Server live since the promise did not reject. An endpoint /ready will be added to your app which will first call the given ready function, then await the returned promise and then respond with 500 Server not ready since the promise rejected.

Passing promises

app.register(plugin, {
    live: Promise.resolve(),
    ready: Promise.reject(),
});

An endpoint /live will be added to your app which will await the given promise and then respond with 200 Server live since the promise did not reject. An endpoint /ready will be added to your app which will await the given promise and then respond with 500 Server not ready since the promise rejected.

Setting pathnames

app.register(plugin, {
    livePathname: '/_/health',
    readyPathname: '/_/ready',
    ready: true,
});

An endpoint /_/health will be added to your app which will respond with 200 Server live An endpoint /_/ready will be added to your app which will respond with 500 Server ready

Plugin options

app.register(plugin, {
    logger,
    livePathname,
    readyPathname,
    live,
    ready,
});
namedescriptiontypedefault
loggerlog4j compatible logger (usually pino) to use for logging.object
liveEither boolean value, function or promise used to determine if app is liveboolean or function => boolean or promise or function => promisetrue
readyEither boolean value, function or promise used to determine if app is readyboolean or function => boolean or promise or function => promisefalse
livePathnamePathname for endpoint where live checks will be servedstring/live
readyPathnamePathname for endpoint where ready checks will be servedstring/ready