support hapi route configuration defaults
(a transform written for loveboat)
In hapi route defaults can be specified for a connection, but not on a per-plugin basis. This loveboat transform allows you to define route defaults per plugin.
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([{ transform: require('loveboat-defaults'), options: { defaults: {/* Specify route defaults */} } }]);
and 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,
// specifying your route defaults
server.routeTransforms([{
transform: require('loveboat-defaults'),
options: {
defaults: {
config: {
cache: {
privacy: 'public'
}
}
}
}
}]);
// 3. Configure your routes!
// This route will have public caching enabled
server.loveboat({
method: 'get',
path: '/some/endpoint',
handler: handler
});
});
The options for this transform should be an object of the format,
-
defaults
- an object specifying route configuration defaults. -
shallow
- (optional) an array of strings specifying route config keys that should be shallow copied rather than merged deeply when applying defaults. SeeHoek.applyToDefaultsWithShallow()
.