nuxt / nuxt

The Intuitive Vue Framework.
https://nuxt.com
MIT License
54.91k stars 5.02k forks source link

Router params 'undefined' in server middleware #26924

Closed krisflajs closed 6 months ago

krisflajs commented 6 months ago

Environment

Reproduction

https://stackblitz.com/edit/github-nyobao-hs48va?file=server%2Fmiddleware%2Fconsole.ts

Describe the bug

When trying to access a route param in the API part (e.g. the id from server/api/[id]/test.get.ts) in the server middleware (e.g. server/middleware/console.ts), the params are always undefined, although they are then present in the actual event handler of the route.

Additional context

No response

Logs

No response

stackblitz[bot] commented 6 months ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

manniL commented 6 months ago

The nitro middleware has now knowledge about "how the route resolves" and possible params. You could use a wrapped handler for the routes needing some functionality (more info in the docs).