hapi-hi
v3.0.0
Published
Status route for your server
Downloads
2
Maintainers
Readme
hapi-hi
Status route for your server
This hapi plugin adds a GET /status
route to your app so that you can check the health of your service by making an HTTP request.
Why?
- Provides useful metrics about your server.
- Response format is friendly to humans and machines.
- Knowing service health helps you recover from errors.
Install
npm install hapi-hi
Usage
Register the plugin on your server to provide the health check endpoint.
const hapi = require('@hapi/hapi');
const hi = require('hapi-hi');
const server = hapi.server();
const init = async () => {
await server.register({
plugin : hi,
options : {
cwd : __dirname
}
});
await server.start();
console.log('Server ready:', server.info.uri);
};
init();
Visiting /status
will return a JSON response with app info because of this plugin.
{
"appName" : "my-project",
"appVersion" : "1.0.0",
"statusCode" : 200,
"status" : "OK",
"time" : "2016-10-06T13:48:10.586Z",
"process" : {
"uptime" : 519163.478,
"title" : "node /srv/my-project/bin/my-project.js",
"version" : "12.0.0",
"pid" : 23794,
}
}
API
Routes
GET /status
Tags: health
, monitor
, status
Returns an object that contains properties useful for checking the status of your server, including appName
, appVersion
, statusCode
, status
, time
, and a process
object with details about the Node.js process.
Plugin options
Type: object
cwd
Type: string
Default: process.cwd()
Where to begin a find-up search for your project's package.json. Used to provide the name and version of your app in the status route response.
noConflict
Type: boolean
Default: false
Apply a /__${appName}
prefix to the status route, where ${appName}
is replaced with the name
from your package.json. This is useful for reverse proxies to remain transparent (e.g. ensure they don't accidentally block access to a file called status
).
Contributing
See our contributing guidelines for more details.
- Fork it.
- Make a feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request.
License
Go make something, dang it.