1.5.0 • Published 8 years ago

hapi-router-coffee v1.5.0

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

Hapi Router Coffee

Build Status Coverage Status

An Opinionated Route Loader for Hapi for CoffeeScript files.

This fork does two things, which may interest you:
1. Written in CoffeeScript (and not compiled to JS), so it can autoload .coffee files.
2. Allows you to pass options to the routes, and merge in the options already on the route.

Setup

$ npm install hapi-router-coffee --save

I assume you're writing in CoffeeScript, right?

server.register {
  register: require('hapi-router-coffee')
  options:
    routesDir: "#{__dirname}/routes/"
}, (err)->
  throw err if err
}

Options

The following required options should be provided at registration:

  • routesDir: the path to your routes directory
  • routesOptions : Options to pass into the config of each route.

Note that the options are not really needed, since you can just use the Hapi server for options. This may be useful in the future though!

server = new Hapi.Server({
    connections:
      routes:
        payload:
          timeout: no # Sets payload timeout to false on ALL routes.
})

Specifying Routes

Any .js or .coffee files in your routes directory will be loaded - supports nested routes.

Example route file:

module.exports = [
  {
    path: '/test1',
    method: 'GET',
    handler: function (request, reply) {
      reply('hello');
    }
  },
  {
    path: '/test2',
    method: 'GET',
    handler: function (request, reply) {
      reply('hello');
    }
  }
]
1.5.0

8 years ago

1.4.0

8 years ago

1.3.0

8 years ago

1.2.0

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago