I have a use-case where I would like to call a middleware after the response went through the route handler. The docs describe that the standard server middleware only runs BEFORE the request is handled (https://nuxt.com/docs/guide/directory-structure/server).
What I'd like to accomplish is:
// file: server/api/test/index.ts
export default defineEventHandler(async (event) => {
return { "test": true }
})
When I call the endpoint via GET /api/test I would like the response to be:
{ "result": { "test": true } }
So basically mapping all APIs response in a object with key "result". This is quite easy to do with express middleware and other frameworks as you can usually await the route handler's result and then just wrap the result in the object.
How can this be accomplished with Nuxt 3 Middleware?