1.1.0 • Published 9 years ago

hapi-auto-routes v1.1.0

Weekly downloads
37
License
MIT
Repository
github
Last release
9 years ago

#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

1.1.0

9 years ago

1.0.3

11 years ago

1.0.2

11 years ago

1.0.1

11 years ago

1.0.0

11 years ago