有人有使用 Koa 2 的简单示例吗?
const n = next({ dev })
const handle = n.getRequestHandler()
n.prepare()
.then(() => {
const app = new Koa()
const router = new Router()
router.get('*', async ctx => {
await handle(ctx.req, ctx.res)
ctx.respond = false
})
app.use(async (ctx, next) => {
// Koa doesn't seems to set the default statusCode.
// So, this middleware does that
ctx.res.statusCode = 200
await next()
})
app.use(router.routes())
app.listen(3000)
})
@timneutkens因为 Node 现在有 async/await,Koa 2.0.1 才在 3 天前发布😄 我想更新示例以使用此版本是有意义的。
没错,我会创建一张新票。
最有用的评论