hapi-auto-route
hapi-auto-route is a hapi plugin that lets you load route objects automatically from a directory. And allow routes path to be prefixed.
Maintainer: Sitraka Ratsimba
Installation
For Hapi >= v17
:
npm i -S hapi-auto-route
For Hapi v16.x.x
:
npm i -S hapi-auto-route@1.1.0
Code Example
Suppose your directory looks like this:
node_modules/
routes/
home.js
server.js
package.json
// routes/home.js'use strict'; moduleexports = method: 'GET' path: '/' 'Hello';
// server.js'use strict'; const Path = ;const Hapi = ; const server = Hapi; const init = async { await server; await serverstart; console;}; process; ;
Now, you can start the server and see Hello
at http://localhost:3000
.
API
routes_dir
: absolute path to routes directory.required
pattern
: glob pattern used to find route files. Defaults to**/!(_)*.js
.use_prefix
: Use directory tree as prefix. Defaults tofalse
.
Contributing
If you find a bug in the source code or a mistake in the documentation, you can help us by submitting an issue or a pull request with a fix.
Licence
This project is licensed under the MIT License - see the LICENSE file for details.