@cdxoo/switch-koa-compose

1.1.0 • 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 ]
});

// "by" can also be a function
const middleware = switchComposition({
    by: (context) => context.someFunctionMaybe(),
    /* ... */
});

Package Sidebar

Install

npm i @cdxoo/switch-koa-compose

Weekly Downloads

10

Version

1.1.0

License

MIT

Unpacked Size

18.6 kB

Total Files

4

Last publish

Collaborators

  • cdxoo