https://github.com/lwhiteley/feathers-alive-ready
feathersjs health check endpoints
https://github.com/lwhiteley/feathers-alive-ready
feathers feathersjs health health-checks healthcheck healthcheck-endpoint readiness
Last synced: 12 months ago
JSON representation
feathersjs health check endpoints
- Host: GitHub
- URL: https://github.com/lwhiteley/feathers-alive-ready
- Owner: lwhiteley
- License: mit
- Created: 2020-06-14T21:39:34.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-24T02:59:53.000Z (about 3 years ago)
- Last Synced: 2024-04-24T15:19:37.007Z (almost 2 years ago)
- Topics: feathers, feathersjs, health, health-checks, healthcheck, healthcheck-endpoint, readiness
- Language: TypeScript
- Size: 488 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# feathers-alive-ready
[](https://badge.fury.io/js/feathers-alive-ready)
[](https://github.com/lwhiteley/feathers-alive-ready)
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
```json
// default.json
// add any number of arbitrary keys here, mongoose is just an example
{
"readiness": {
"mongoose": false
}
}
```
### Step 2: Configure the plugin
```js
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
```js
// ./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.
| Property | default | description |
| ---------- | :-------------- | ----------------------------------------------------------------------------------------------------------- |
| configKey | `readiness` | which property to look for the readiness config in the app config files |
| returnData | false | determines if to return the readiness object in the ready endpoint |
| aliveUrl | `/health/alive` | alive endpoint |
| readyUrl | `/health/ready` | ready endpoint |
| customOnly | false | will 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]` |
```js
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
```js
app.configure(
health({
customOnly: true,
custom: [(app: Application) => !!app.get('mongooseClient')],
}),
);
```
## License
Licensed under the [MIT license](LICENSE).