1.2.2 • Published 4 years ago

feathers-alive-ready v1.2.2

Weekly downloads
22
License
MIT
Repository
github
Last release
4 years ago

feathers-alive-ready

npm version test-lib

feathersjs health check endpoints

a plugin to add health check endpoints to a feathersjs application

Installation

// install peer dependencies
npm install --save @feathersjs/errors @feathersjs/express @feathersjs/feathers

// install module
npm install --save feathers-alive-ready

Setup

Step 1: Add readiness config

// default.json
// add any number of arbitrary keys here, mongoose is just an example
{
  "readiness": {
    "mongoose": false
  }
}

Step 2: Configure the plugin

import feathers from '@feathersjs/feathers';
import { health } from 'feathers-alive-ready';
import mongoose from './mongoose';

// Initialize the application
const app = feathers();

// Initialize the plugin before all other services that may require
// a health check
app.configure(health());
app.configure(mongoose);

What happens in step 2

By default, the plugin will add two endponts /health/alive and /health/ready to the application.

Step 3: Tell the application when your service is ready

Use the helper method below to tell the application your service is now ready

// ./mongoose.ts

import { setReady } from 'feathers-alive-ready';

export default function (app: Application) {
  mongoose
    .connect(app.get('mongodb'), {
      useCreateIndex: true,
      useNewUrlParser: true,
      useUnifiedTopology: true,
    })
    .then(() => {
      setReady(app, 'mongoose');
    })
    .catch((err) => {
      logger.error(err);
      process.exit(1);
    });

  mongoose.Promise = global.Promise;

  app.set('mongooseClient', mongoose);
}

The ready endpoint will not return a positive result until all keys in the readiness config are truthy

Configure

You can customize the plugin by passing in options.

Propertydefaultdescription
configKeyreadinesswhich property to look for the readiness config in the app config files
returnDatafalsedetermines if to return the readiness object in the ready endpoint
aliveUrl/health/alivealive endpoint
readyUrl/health/readyready endpoint
customOnlyfalsewill only honour custom checks when set to true, if false will honour both readiness config + custom checks
custom[]an array of functions that return a boolean eg. [(app) => true]
app.configure(
  health({
    configKey: 'readiness',
    returnData: true,
    aliveUrl: '/health/alive',
    readyUrl: '/health/ready',
  }),
);

Optional Configuration

If you want to do your own custom checks then do the following

app.configure(
  health({
    customOnly: true,
    custom: [(app: Application) => !!app.get('mongooseClient')],
  }),
);

License

Licensed under the MIT license.

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.5

4 years ago

0.0.6

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago