Skip to content

Latest commit

 

History

History
49 lines (33 loc) · 780 Bytes

README.md

File metadata and controls

49 lines (33 loc) · 780 Bytes

Koa Middleware Multiplexer

Multiplex Koa's middleware.

Install

$ npm i koa-middleware-multiplexer

Usage

const multiplexer = require('koa-middleware-multiplexer');

router.post('/user', multiplexer.multiplex(
  (ctx) => ctx.query.type,
  [
    ['admin', signUpAdmin],
    ['user', signUpUser],
  ],
));

multiplex

function multiplex(condition, functions, options = { errorHandler, checkExist: false })

Error Handel

function errorHandel(ctx, error) {
  ctx.response.status = error.status || error.statusCode || 500;
  ctx.response.body = { message: error.message || 'Undefined error' };
}