Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sholladay/hapi-hi
Status route for your server.
https://github.com/sholladay/hapi-hi
check hapi health heartbeat ping plugin server status
Last synced: 1 day ago
JSON representation
Status route for your server.
- Host: GitHub
- URL: https://github.com/sholladay/hapi-hi
- Owner: sholladay
- License: mpl-2.0
- Created: 2016-10-06T03:07:52.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-01-13T17:39:38.000Z (about 5 years ago)
- Last Synced: 2024-04-14T00:25:06.621Z (10 months ago)
- Topics: check, hapi, health, heartbeat, ping, plugin, server, status
- Language: JavaScript
- Size: 18.6 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# hapi-hi [![Build status for hapi Hi](https://travis-ci.com/sholladay/hapi-hi.svg?branch=master "Build Status")](https://travis-ci.com/sholladay/hapi-hi "Builds")
> Status route for your server
This [hapi](https://hapijs.com) 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
```sh
npm install hapi-hi
```## Usage
Register the plugin on your server to provide the health check endpoint.
```js
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.
```json
{
"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](https://github.com/sindresorhus/read-pkg-up) 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](https://github.com/sholladay/hapi-hi/blob/master/CONTRIBUTING.md "Guidelines for participating in this project") for more details.
1. [Fork it](https://github.com/sholladay/hapi-hi/fork).
2. Make a feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. [Submit a pull request](https://github.com/sholladay/hapi-hi/compare "Submit code to this project for review").## License
[MPL-2.0](https://github.com/sholladay/hapi-hi/blob/master/LICENSE "License for hapi-hi") © [Seth Holladay](https://seth-holladay.com "Author of hapi-hi")
Go make something, dang it.