For questions related to the second generation of the Koa web framework for Node.js, whose middleware function signature changes from use of generators to async/await.
koa2 should be used for questions related to the second generation of the Koa framework. Note also the koa tag for questions about the previous version.
Sample
Koa2 changes the middleware function signature:
// Middleware functions use async where required. Must return a promise.
app.use(async (ctx, next) => {
try {
await next() // next is now a function
} catch (err) {
ctx.body = { message: err.message }
ctx.status = err.status || 500
}
})
app.use(async ctx => {
const user = await User.getById(this.session.userid) // await instead of yield
ctx.body = user // ctx instead of this
})
References