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

Abierto
#5,161 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
1-2 días
Aptitud para principiantes
49/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
typescript
Área
backend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
TypeScript
Estrellas
11.5k
Forks
968
Merge medio
4 d 9 h
PR fusionados (30 d)
64

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de nitrojs/nitro

Todos los issues de nitrojs/nitro

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.