Skip to content

Latest commit

 

History

History
63 lines (44 loc) · 1.74 KB

README.md

File metadata and controls

63 lines (44 loc) · 1.74 KB

hapi-auto-route

Semver Dependency Status devDependency Status

Autoloads hapi routes.

Installation

Just type yarn add hapi-auto-route or npm i -S hapi-auto-route.

Code Example

Suppose your directory looks like this:

node_modules/
routes/
  home.js
server.js
package.json
// routes/home.js
module.exports = {
    method: 'GET',
    path: '/',
    handler: (request, reply) => reply('Hello');
}
// server.js
'use strict';

const Hapi = require('hapi');
const server = new Hapi.Server();
server.connection({ port: 3000, labels: ['web'] });
server.register(require('hapi-auto-route'), (error) => {

    if(error) throw error;
    server.start();
});

Now, you can start the server and see Hello at http://localhost:3000.

API

  • dir: the absolute path to the route directories. Defaults to process.cwd() + '/routes'.
  • pattern: glob pattern used to find route files. Defaults to /**/!(_)*.js.
  • prefix: Use directory tree as prefix. Defaults to true.

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.txt file for details.