Routed middleware: params, tracing and ordering docs

Open
#5,091 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
51/100
Issue type
Documentation
Clarity
Mostly clear
Activity status
Active
Tech stack
typescript

Research direction

Read docs/1.docs/50.lifecycle.md and docs/1.docs/5.routing.md, then trace routed middleware through src/runtime/internal/app.ts and #nitro/virtual/routing to confirm the behavior described. Document that routed middleware run after global middleware and follow rou3 matchAll order, from least to most specific. Done when both docs explain the ordering clearly.

Written by the indexing model from the issue text.

Description

routing

Follow-up from #5090. Routed middleware (server/middleware with a route, dispatched by createRoutedMiddleware in src/runtime/internal/app.ts) has a few gaps compared to h3's app.use(route, mw):

  • Params: h3 sets event.context.middlewareParams from the matched route. Nitro's routed dispatcher drops the params from findRoutedMiddleware, so a middleware on /users/:id cannot read id.
  • Tracing: the dispatcher is opted out of h3/tracing (markUntraced), and routed middleware are not wrapped with wrapHandlerWithTracing in #nitro/virtual/routing (only routes are), so they produce no spans.
  • Docs: routed middleware run after global middleware, in rou3 matchAll order (least to most specific: /**, /:a/users, /api/**, /api/:id, /api/users), not in registration order. docs/1.docs/50.lifecycle.md and docs/1.docs/5.routing.md do not say this.

Opened with AI assistance.

Dominant language
TypeScript
Stars
11.5k
Forks
968
Avg merge
4d 9h
Merged PRs (30d)
64

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nitrojs/nitro

All issues in nitrojs/nitro

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.