1.0.1 • Published 1 year ago

@cdxoo/switch-koa-compose v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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