@cdxoo/switch-koa-compose

1.0.1 • Public • Published

@cdxoo/switch-koa-composition

Switches nested middleware stacks based on context value indicated by given json pointer.

const switchComposition = require('@cdxoo/switch-koa-compose');

const middleware = switchComposition({
    by: '/json/pointer/to/value/in/context',
    branches: {
        'foo': [ barMiddleware, anotherBarMiddleware ],
        'bar': [ fooMiddleware, anotherFooMiddleware ],
    },

    // optional; will throw when omitted and no branch was found
    fallback: [ someFallbackMiddlware ]
});

Package Sidebar

Install

npm i @cdxoo/switch-koa-compose

Weekly Downloads

6

Version

1.0.1

License

MIT

Unpacked Size

17.2 kB

Total Files

4

Last publish

Collaborators

  • cdxoo