Multiplex Koa's middleware.
$ npm i koa-middleware-multiplexer
const multiplexer = require('koa-middleware-multiplexer');
router.post('/user', multiplexer.multiplex(
(ctx) => ctx.query.type,
[
['admin', signUpAdmin],
['user', signUpUser],
],
));
function multiplex(condition, functions, options = { errorHandler, checkExist: false })
function errorHandel(ctx, error) {
ctx.response.status = error.status || error.statusCode || 500;
ctx.response.body = { message: error.message || 'Undefined error' };
}