about middleware and logs collection
xiaoyue9527 opened this issue · 1 comments
xiaoyue9527 commented
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
- Read the contribution guide.
- Check existing discussions and issues.
xiaoyue9527 commented
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)
})