Skip to content

GMKR/hapi-auto-routes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#hapi-auto-routes hapi-auto-routes allows you to automatically register all routes from matching files.

##Installation npm install hapi-auto-routes --save ##Usage ####server.js

const Hapi = require('hapi')
const server = new Hapi.Server()
const routes = require('../index')
server.connection({port: 3000});

//Register all routes from files matching pattern *.route.js
routes.bind(server).register({
  pattern: __dirname   '*.route.js',
});

server.start((err) => {
  if (err) {
    throw err;
  }
  console.log(`Server running at: ${server.info.uri}`);
});

####index.route.js

const helloOne = {
  method: 'GET',
  path: '/hello-one',
  config: {
    handler: (request, reply) => {
      return reply('Hello world one!')
    }
  }
};

const helloTwo = {
  method: 'GET',
  path: '/hello-two',
  config: {
    handler: (request, reply) => {
      return reply('Hello world two!')
    }
  }
};

module.exports = [helloOne, helloTwo]

inspired by Mongoload

About

Automatically register Hapi Routes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published