routeRules never reach the IPX handler: headers are ignored and cache rules silently don't wrap it

Aperta
#2,392 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à
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
53/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
docker, node.js, nuxt, typescript

Direzione di ricerca

Start with the module handler registration in @nuxt/image and Nitro’s route-rule processing; the report says the IPX handler is added after route rules are processed. Check how fromNodeMiddleware(createIPXNodeHandler(...)) handles headers and whether a cached wrapper can be applied. Done means /_ipx/** headers and cache rules work on the self-hosted node preset, with a regression test covering both.

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

Descrizione

Environment
  • @nuxt/image 2.1.0 (ipx 4.0.0-beta.1), Nuxt 4.5, Nitro node-server preset, self-hosted (Docker behind Traefik)
Describe the bug

routeRules targeting /_ipx/** never affect the IPX handler — neither headers nor cache:

  1. Headers are ignored. '/_ipx/**': { headers: { 'cache-control': '…' } } has no effect; the handler writes its own headers via the node middleware and ends the response (fromNodeMiddleware(createIPXNodeHandler(…))). This is probably the root cause behind #992 / #704.
  2. cache rules are silently not applied. With '/_ipx/**': { cache: { maxAge: 2592000 } } the built server still registers the handler unwrapped — grep "'/_ipx/\*\*'" .output/server/chunks/nitro/nitro.mjs shows the plain handler entry, no cachedEventHandler, and no cache entries are ever written. The module pushes its handler into nitro.options.handlers after route-rule processing, so the rule never wraps it.
  3. A scanned server route on the same pattern (server/routes/_ipx/[...].ts with defineCachedEventHandler) cannot take over either: both land on the same radix node and the later (module) registration wins.
Why it matters

On self-hosted SSR there is no supported way to put a server-side output cache in front of the IPX transforms. Every variant is re-encoded from the original per first-time visitor; on our vServer that is ~150–450 ms CPU per WebP hero variant (≈0.4–2.8 s for AVIF), per request, as long as no browser cache exists. ipx.fs.maxAge only sets browser cache headers. Related: #795 (SSG cache), #329.

Reproduction
// nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@nuxt/image'],
  nitro: {
    routeRules: { '/_ipx/**': { cache: { maxAge: 2592000 } } },
    storage: { cache: { driver: 'fs', base: './.cache/nitro' } },
  },
})

Build with the node preset, request any /_ipx/... URL twice: identical timings, no cache entries on disk, and the built nitro.mjs lists the /_ipx/** handler without a cache wrapper.

Expected behaviour

Either routeRules (headers and cache) apply to the IPX route like to any other route, or the module offers a documented output-cache option for SSR (e.g. an unstorage-backed transform cache).

Workaround we tried

Renaming the module handler's route to an internal path via a tiny module in nuxt.hook('nitro:init') (also moving runtimeConfig.ipx.baseURL) and serving /_ipx/** from a scanned defineCachedEventHandler proxy route works, but it depends on module internals, so we dropped it. Happy to open a PR if you indicate the preferred direction.

Lingua principale
TypeScript
Stelle
1.6k
Fork
335
Merge medio
3g 13h
PR unite (30g)
15

Preparare l'ambiente

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 nuxt/image

Tutte le issue di nuxt/image

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.