Package Exports
- hapi-router
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (hapi-router) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Route loader for hapi.
Setup
$ npm install hapi-router
server.register({
register: require('hapi-router')
options: {
routes: 'src/**/*Route.js' // uses glob to include files
}
}, function (err) {
if (err) throw err;
});
Options
The following required options
should be provided at registration:
routes
: the glob pattern you would like to include
The following optional options
can be provided at registration:
ignore
: the pattern or an array of patterns to excludecwd
: the current working directory in which to search (defaults toprocess.cwd()
)
Specifying Routes
Any files that match your routes glob will be loaded
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');
}
}
]
Glob Primer
From isaacs:
"Globs" are the patterns you type when you do stuff like ls *.js
on
the command line, or put build/*
in a .gitignore
file.
The following characters have special magic meaning when used in a path portion:
*
Matches 0 or more characters in a single path portion?
Matches 1 character[...]
Matches a range of characters, similar to a RegExp range. If the first character of the range is!
or^
then it matches any character not in the range.!(pattern|pattern|pattern)
Matches anything that does not match any of the patterns provided.?(pattern|pattern|pattern)
Matches zero or one occurrence of the patterns provided.+(pattern|pattern|pattern)
Matches one or more occurrences of the patterns provided.*(a|b|c)
Matches zero or more occurrences of the patterns provided@(pattern|pat*|pat?erN)
Matches exactly one of the patterns provided**
If a "globstar" is alone in a path portion, then it matches zero or more directories and subdirectories searching for matches. It does not crawl symlinked directories.
Example globs:
'routes/*.js' // match all js files in the routes directory
'routes/**/*.js' // recursively match all js files in the routes directory
'**/*Route.js' // match all js files that end with 'Route'