File-based hapi plugin composer
This library will wire your hapi plugin together based simply upon where you place files. It has the ability to call every configuration-related method in the hapi plugin API. This means many good things.
To name a few,
- Route configurations placed in your
routes/
directory will be registered usingserver.route()
. - You can place your authentication scheme in
auth/schemes.js
rather than callingserver.auth.scheme()
. - You can provision a cache simply by placing its configuration in
caches/my-cache-name.js
, and forget aboutserver.cache.provision()
. - Where applicable, any of these files can be configured as JSON.
- You can teach haute-couture how to use your own custom server decorations.
- You can still write all the custom plugin code you desire.
Again, haute-couture understands 23 hapi plugin methods– those for server methods, custom handler types, server/request decorations, request lifecycle extensions, route configuration, cookie definitions, loveboat routes and transforms, vision view managers, dogwater or schwifty model definitions, chairo action-methods, and plenty more. It can also be used as an alternative to glue for composing a server.
See also the API Reference
This library is actually not used as a hapi plugin. Think of it instead as a useful subroutine of any hapi plugin. The full documentation of the files and directories it recognizes can be found in the API.
Here's an example of a very simple plugin that registers a single "pinger" route.
const HauteCouture = require('haute-couture');
// Either...
// 1. a plugin wired with haute-couture plus custom logic
module.exports = (server, options, next) => {
HauteCouture.using()(server, options, (err) => {
// Handle err, do custom plugin duties
return next();
});
};
// 2. a plugin entirely wired using haute-couture
module.exports = HauteCouture.using();
module.exports.attributes = {
name: 'my-hapi-plugin'
};
// Note, this could also export an array of routes
module.exports = {
method: 'get',
path: '/',
config: {
// The route id 'pinger' will be assigned
// automatically from the filename
handler: (request, reply) => {
reply({ ping: 'pong' });
}
}
};