Skip to content

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

Open

Description

@ckoch1979silentservice

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 IPX max-age configuration doesn't apply #992 / Change IPX Cache-Control max-age #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.

Activity

  1. lafllamme commented on Nov 24, 2026

    @lafllamme

    I tried this locally with Nuxt 4.5.0, @nuxt/image 2.1.0 and ipx 4.0.0-beta.1. With a cache rule on /_ipx/**, my image request timed out; without the cache rule, it returned the image. I saw the timeout with Nitro 2.13.6 and 2.14.0. My setup ran locally on macOS with the Node server preset, without Docker or Traefik.

    I also tried @nuxt/image 2.2.1, which uses a different IPX handler. There, the first request returned the PNG, but the cached response was {} with an application/json content type. Nitro was serializing the Web Response instead of its body and headers.

    I opened nitrojs/nitro-v2#51 for that Nitro v2 cache behavior. With the patch applied locally, the first and cached requests returned identical PNG bytes and the expected content type.

    This doesn't establish that the PR fixes the timeout on 2.1.0 or all the behavior reported here; those still need checking.

  2. added theissue type on Nov 27, 2026
  3. added
    bug
    and removed on Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugupstream

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions