Allow middleware or a plugin to run before public assets are served

Aperta
#5,161 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
1-2 giorni
Idoneità per principianti
49/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
backend

Direzione di ricerca

Start by reading the Nitro v3 request handling path that serves public assets before global middleware, along with the request hook and plugin behavior described in the issue. Compare the two suggested API options and how wrapping nitroApp.fetch currently works. Done means a supported approach can guard static asset responses and the issue’s example requests behave as expected.

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

Descrizione

Describe the feature

In Nitro v3 the static handler runs before all global middleware, so server/middleware/* never sees a request for a public file, and the request hook cannot stop a request (a thrown error is caught and the chain continues). There is no supported way to guard every response: rejecting an unexpected Host, redirecting to a canonical host, or answering a malformed path.

Repro (3.0.261103-rc, node-server): public/robots.txt plus server/middleware/guard.ts returning new Response("no", { status: 403 }). GET /robots.txt → 200, any route → 403. A request hook throwing HTTPError(403) blocks neither.

Could middleware opt in to running before static files, or could the request hook return a Response?

Additional information

Today we wrap nitroApp.fetch in a plugin.

Lingua principale
TypeScript
Stelle
11.5k
Fork
968
Merge medio
4g 9h
PR unite (30g)
64

Preparare l'ambiente

Apri in Codespaces

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

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

Tutte le issue di nitrojs/nitro

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.