hapi-route-auto-reg

1.0.4 • Public • Published

Hapi route auto-registration

Build Status NPM version Dependencies

Automatically scans the directory and registers the routes it finds within

installation:

npm install hapi-route-auto-reg

usage:

var hapi = require("hapi");

var server = Hapi.createServer('127.0.0.1', 3000, {});

server.pack.register([
  {
    plugin: require("hapi-route-auto-reg"),
    options: {
      directory: './path/to/routes'
    }
  }], function(err){
    if(err) {
      throw err;
    }
    
    server.start(function(){
      server.log('server started...');
    });
});

Scans the given directory for .js files which export a method .routes(plugin) and invokes them.

The routes files should look like this:

module.exports.routes = function(plugin){
    plugin.route([
        {
            method: 'GET',
            path: '/my/test/route',
            config: {
                handler: function(request, reply) {
                    ...
                }
            }
        }
    ]);
}

Readme

Keywords

Package Sidebar

Install

npm i hapi-route-auto-reg

Weekly Downloads

3

Version

1.0.4

License

MIT

Last publish

Collaborators

  • acolchado
  • arnoldzokas
  • matteofigus
  • ryantomlinson
  • andyroyle
  • stevejhiggs