工信部的网站备案,建站之星管理中心,长沙百度网络推广,深圳市龙岗区Koa 和 Express 都会使用到中间件 Express的中间件是顺序执行#xff0c;从第一个中间件执行到最后一个中间件#xff0c;发出响应如上图 Koa是从第一个中间件开始执行#xff0c;遇到 next 进入下一个中间件#xff0c;一直执行到最后一个中间件#xff0c;在逆序#x…
Koa 和 Express 都会使用到中间件 Express的中间件是顺序执行从第一个中间件执行到最后一个中间件发出响应如上图 Koa是从第一个中间件开始执行遇到 next 进入下一个中间件一直执行到最后一个中间件在逆序执行上一个中间件 next 之后的代码一直到第一个中间件执行结束才发出响应如上图
见代码
const Koa require(koa2);
const app new Koa();
const port 9000;app.use(async (ctx, next){console.log(1)await next();console.log(2)
})app.use(async (ctx, next){console.log(3)await next();console.log(4)
})app.use(async (ctx){console.log(5)
})app.listen(port, (){console.log(Server is running at http://localhost:port);
})
那么在浏览器刷新后控制台得到的顺序是