https://github.com/igorkosta/chav
chav is a hapi plugin to create static routes from json files
https://github.com/igorkosta/chav
hapi hapi-plugin hapijs json node npm
Last synced: 2 months ago
JSON representation
chav is a hapi plugin to create static routes from json files
- Host: GitHub
- URL: https://github.com/igorkosta/chav
- Owner: igorkosta
- License: mit
- Created: 2016-09-14T08:48:24.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-02-06T10:24:07.000Z (over 9 years ago)
- Last Synced: 2025-08-27T22:28:32.237Z (11 months ago)
- Topics: hapi, hapi-plugin, hapijs, json, node, npm
- Language: JavaScript
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Chav [ ](https://codeship.com/projects/175290)
Sometimes in life you just want to serve static `json` content as an API route.
`chav` is a hapi.js plugin to serve a static `json` file as an API route. Per default the file under `static/static.json` is served as `GET /statics`
## Installation
`npm install --save chav`
## Usage
As long as you don't provide any options, we'll assume that the file you want to be served is called `static.json` and is located in the `static` folder of your app.
The `/static` route is not protected.
These are the defaults we're using. If you want to override the `servable` or the `path` just provide your `options` on plugin registration.
```
const defaults = {
servable: 'static/static.json',
path: '/statics',
tags: ['static', 'route'],
description: 'Renders static route defined in a file',
responses: {
statusCode: 400,
message: 'No static routes found'
},
auth: false
};
```
You can override `servable`, `path`, `tags` and `description`.
When you register your plugin with e.g. `glue`:
```
{
"plugin": {
"register": "chav",
"options": {
"servable" : "static/foobar.json"
}
}
}
```
## TODOs
- Whenever the `json` file has more than one array (see example below), try to also offer the `/statics/beers` and `/statics/snacks` routes
```
{
"beers" : [
],
"snacks" : [
]
}
```
- Check if the `servable` is actually a `file` or a `directory` and if it's a `directory` serve every file as an API route, e.g. file name is a route name.
## License
[MIT](https://opensource.org/licenses/MIT)