README
loveboat-paths
support listing multiple paths in hapi route config
(a transform written for loveboat)
Usage
This loveboat transform allows you to pass an array of route paths in your hapi route configuration, whereas hapi on its own only supports a single path.
// Ever wish this worked?
server.loveboat({
method: 'get',
path: ['/dogs', '/cats'], // Now it does!
handler: function (request, reply) {
reply('You four-legged animal!');
}
});
To use this transform,
- Make sure the loveboat hapi plugin is registered to your server.
- Tell loveboat that you'd like to use this transform by calling
server.routeTransforms([require('loveboat-paths')])
, possibly listing any other transforms you'd like to use.* - Register your routes using
server.loveboat()
rather thanserver.route()
.
* There are other ways to tell loveboat which transforms to use too! Just check-out the readme.
const Hapi = require('hapi');
const Loveboat = require('loveboat');
const server = new Hapi.Server();
server.connection();
// 1. Register loveboat
server.register(Loveboat, (err) => {
// 2. Tell loveboat to use this transform
server.routeTransforms([
require('loveboat-paths')
]);
// 3. Configure your routes!
server.loveboat({
method: 'get',
path: ['/dogs', '/cats'], // This works!
handler: function (request, reply) {
reply('You four-legged animal!');
}
});
});