Skip to content

bmleight/haute-couture

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

haute-couture

File-based hapi plugin composer

Build Status Coverage Status

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 using server.route().
  • You can place your authentication scheme in auth/schemes.js rather than calling server.auth.scheme().
  • You can provision a cache simply by placing its configuration in caches/my-cache-name.js, and forget about server.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.

Usage

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.

index.js

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'
};

routes/pinger.js

// 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' });
    }
  }
};

About

File-based hapi plugin composer

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%