`/**` redirect and proxy route rules return 400 with `baseURL`

Aperta
#2 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
70/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
backend

Direzione di ricerca

Start in src/runtime/internal/app.ts and trace how the route rules handler passes event.path to resolveRedirectTarget and resolveRuleTarget, then read the scope checks and the related route rule tests. Reproduce with baseURL "/base/" and the documented redirect or proxy rule; done means the request reaches the expected target and the scope checks still apply to the final path.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug route-rules

With a baseURL, redirect and proxy route rules that use /** return 400 at runtime.

Example: baseURL: "/base/" with routeRules: { "/old/**": { redirect: "/new/**" } }. A request to /base/old/x gets a 400 instead of a redirect to /new/x.

Cause: the route rules handler runs on the root h3 app (src/runtime/internal/app.ts), so event.path still includes the baseURL. Matching strips it (getRouteRules), but resolveRedirectTarget and resolveRuleTarget get the raw event.path. _redirectStripBase / _proxyStripBase come from the rule key (/old) without the base, so isPathInScope("/base/old/x", "/old") fails. Before the scope checks were added (353eff5c), the same mismatch made withoutBase a no-op and produced a wrong target (/new/base/old/x) instead.

Possible fix: strip app.baseURL from event.path before calling these helpers, or prefix the strip base with it. The scope checks must still run on the final path.

This came up while reviewing nitrojs/nitro#4821 (umbrella: nitrojs/nitro#4707). Main's route rules are implemented differently and were not checked.

Opened with AI assistance.

Lingua principale
TypeScript
Stelle
1
Fork
6
Merge medio
1g 2h
PR unite (30g)
20

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nitrojs/nitro-v2

Tutte le issue di nitrojs/nitro-v2

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.