Open zhaobinglong opened 3 years ago
洋葱模型的顺序,类似于vue中嵌套组件的生命周期,从外到里,然后从里到外
const Koa = require('koa')
const app = new Koa()
const mid1 = async (ctx, next) => {
ctx.body = '前:' + '1\n'
await next()
ctx.body = ctx.body + '后:' + '1\n'
}
const mid2 = async (ctx, next) => {
ctx.body = ctx.body + '前:'+ '2\n'
await next()
ctx.body = ctx.body + '后:'+ '2\n'
}
const mid3 = async (ctx, next) => {
ctx.body = ctx.body + '前:'+ '3\n'
await next()
ctx.body = ctx.body + '后:'+ '3\n'
}
app.use(mid1)
app.use(mid2)
app.use(mid3)
app.listen(3000)
koa框架组成
req
做了抽象和封装res
做了抽象和封装与express区别
启动应用