Skip to content

koa

Posted on:June 5, 2023 at 05:24 AM

const middleware: (() => unknown) []=[]

function compose(middlewares) {
  return (ctx) => {
    const dispatch = (i) => {
      const middleware = middlewares[i];
      if (i === middlewares.length) {
        return;
      }
      return middleware(ctx, () => dispatch(i + 1));
    };
    return dispatch(0);
  };
}