nuxt / framework

Old repo of Nuxt 3 framework, now on nuxt/nuxt

Home Page:https://nuxt.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

about middleware and logs collection

xiaoyue9527 opened this issue · comments

Describe the feature

We need to record API time consumption and other logs. Is there any related function to execute the middleware after the request ends?

If there is no relevant solution, will subsequent versions have relevant functions?

Additional information

  • Would you be willing to help implement this feature?
  • Could this feature be implemented as a module?

Final checks

My previous method was to enter the directory 'server/routes/urls/[...] Start a universal route in ts', and then call the middleware in the view

export default defineEventHandler(async (event) => {
const [url, method] = [event.req.url.split('?')[0], event.req.method]
let result: any
// Before requesting
await middle.bf(event)
// Call the real view
result = await urls[url]method
// After request
middle.af(event)
return msg(event,result)
})