Reuseable healthcheck package to be used by fastify servers and express servers.
- GET
/healthcheck
- default healthcheck is API up - GET
/healthcheck/startz
- default healthcheck is API up - GET
/healthcheck/readyz
- healthcheck is API up and are dependencies up
yarn add @imaware/healthcheck
const options = {
dependencies: {
serviceHealthcheck: 'http://service.healthcheck',
serviceStart: 'http://service.start',
serviceReady: 'http://service.ready',
},
};
import { healthcheck } from '@imaware/healthcheck';
const RouteHandlers = [HealthCheckHandler];
export default fp(async (app: FastifyInstance) => {
/* Pass in app and name of service or API
* app: FastifyInstance
* opts: { name: string }
*/
healthcheck(app, dependencies);
});
import { healthcheck } from '@imaware/healthcheck';
/* Pass in app and name of service or API
* app: express.Application
* opts: { name: string }
*/
healthcheck(app, dependencies);
import { healthcheck } from '@imaware/healthcheck';
healthcheck(app);
Response for /healthcheck
{ "ok": true }
Response for /healthcheck/readyz
{ "ok": true }
Response for /healthcheck/startz
with dependencies
{ "ok": true, "message": "Healthcheck success for service" }
Response for /healthcheck/startz
without dependencies
{ "ok": true, "message": "Healthcheck success" }
dependencies
By default this is not required. You can pass in JSON object as API name (key) and API URI (value). Healthcheck will check each dependency to check if service is up.
const options = {
dependencies: {
serviceHealthcheck: 'http://service.healthcheck',
serviceStart: 'http://service.start',
serviceReady: 'http://service.ready',
},
};