loveboat-paths

support listing multiple paths in hapi route config

Usage no npm install needed!

<script type="module">
  import loveboatPaths from 'https://cdn.skypack.dev/loveboat-paths';
</script>

README

loveboat-paths

support listing multiple paths in hapi route config

(a transform written for loveboat)

Build Status Coverage Status

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,

  1. Make sure the loveboat hapi plugin is registered to your server.
  2. 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.*
  3. Register your routes using server.loveboat() rather than server.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!');
        }
    });

});