# 以下代码,koa 会返回什么数据

更多描述

根据有无 await next() 判断以下代码输出结果

const Koa = require('koa')
const app = new Koa()

app.use(async (ctx, next) => {
  ctx.body = 'hello, 1'
})

app.use(ctx => {
  ctx.body = 'hello, 2'
})

app.listen(3000)
const Koa = require('koa')
const app = new Koa()

app.use(async (ctx, next) => {
  ctx.body = 'hello, 1'
  await next()
})

app.use(ctx => {
  ctx.body = 'hello, 2'
})

app.listen(3000)
const Koa = require('koa')
const app = new Koa()

app.use(async (ctx, next) => {
  await next()
  ctx.body = 'hello, 1'
})

app.use(ctx => {
  ctx.body = 'hello, 2'
})

app.listen(3000)

Issue

欢迎在 Issue 中交流与讨论: Issue 238 (opens new window)

根据 koa 的洋葱模型,返回结果是

hello, 1

hello, 2

hello, 1
Last Updated: 1/17/2021, 2:02:56 PM