Just some lines of code to let you declare hapi routes from a manifest.json
The plugin is actually only a server.route
hapi call, nothing more.
npm install --save hapi-routify
If you use hapi with glue or rejoice, you may want to declare the routes of your application from the manifest.json
:
{
"server": {
"port": 8000
},
"register": {
"plugins": [
"h2o2",
{
"plugin": "hapi-routify",
"options": {
"routes": [{
"method": "GET",
"path": "/{path*}",
"handler": {
"proxy": {
"host": "localhost",
"port": 3000
}
}
}]
}
},
"blipp"
]
}
}
This example uses h2o2 to proxy all your requests to http://localhost:1337.
If you use rejoice there are actually two ways to provide your own handler:
- wrap your
manifest
with the CommonJSmodule.exports
declaration, so you will be able to write a javascript function (seeexamples/manifest.js
) - write a plugin that uses the
server.handler
method provided by hapi (seeexamples/manifest-customHandler.json
andexamples/customHandler/index.js
)
routes
: the array of routes objects you will otherwise pass toserver.route
.
Package | Version | Dev |
---|---|---|
blipp | ^3.0.0 | ✔ |
code | ^5.2.4 | ✔ |
h2o2 | ^8.0.0 | ✔ |
hapi | ^17.8.1 | ✔ |
lab | ^18.0.0 | ✔ |
node-readme | ^0.1.9 | ✔ |
rejoice | ^5.0.1 | ✔ |
Contributions are welcome! Open an issue to report bugs or request features. To contribute with code:
- clone this repository
- install the dependencies with
npm install
- make your changes to the files in the
src/
folder - write tests using lab in the
test/
folder - run tests with
npm test
. try to keep test coverage about 100% - edit the
.README.md
file and build the project again (npm run compile
) - send a pull request against the master branch
g-div
Inspired by garthk's hapi-restify.js gist.