hapi-router-coffee
v1.5.0
Published
An Opinionated Route Loader for Hapi for CoffeeScript files.
Downloads
1
Maintainers
Readme
Hapi Router Coffee
An Opinionated Route Loader for Hapi for CoffeeScript files.
This fork does two things, which may interest you:
- Written in CoffeeScript (and not compiled to JS), so it can autoload .coffee files.
- 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 directoryroutesOptions
: Options to pass into theconfig
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');
}
}
]