Skip to content

CourseDesign/koa-middleware-multiplexer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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' };
}