koa洋葱图

2019-12-10  本文已影响0人  Wrestle_Mania
const m1 = ctx => {
  console.log("m1 start");
};

module.exports = () => async (ctx, next) => {
  m1(ctx);
  await next();
  console.log("m1 end");
};
const m2 = ctx => {
  console.log("m2 start");
};

module.exports = () => async (ctx, next) => {
  m2(ctx);
  await next();
  console.log("m2 end");
};
const m3 = ctx => {
  console.log("m3 start");
};

module.exports = () => async (ctx, next) => {
  m3(ctx);
  await next();
  console.log("m3 end");
};
const Koa = require("koa");
const m1 = require("./middleware/m1");
const m2 = require("./middleware/m2");
const m3 = require("./middleware/m3");

app.use(m1());
app.use(m2());
app.use(m3());

控制台上看到:

m1 start
m2 start
m3 start
m3 end
m2 end
m1 end
上一篇 下一篇

猜你喜欢

热点阅读