by mattwad · 2y ago · 0 comments
In Express, the route handlers send the response directly so your middleware can only be "beforeware".
In Koa, the route handlers update a response object that bubbles back up the stack before it's sent, so you can write both beforeware and afterware (so, real middleware).
For example:
app.use(async (ctx, next) => {
console.log('Request is going down', ctx.request.body)
await next()
console.log('Response is coming up', ctx.response.body)
})