Skip to content

File extension/Image src does not end to server route but 404 #7403

Open
nitrojs/nitro
#4467

Description

@Zareix

Which project does this relate to?

Start

Describe the bug

This behavior is a bit strange so I'll try to explain as best.

I have an API route like that :

// src/routes/api/files.ts
import { createFileRoute } from "@tanstack/react-router";

export const Route = createFileRoute("/api/files")({
  server: {
    handlers: {
      GET: async ({ request }) => {
        return Response.json({
          message: new URL(request.url).searchParams.get("filename"),
        });
    },
  },
});

If I call this endpoint with :

  • http://localhost:3000/api/files?filename=something -> OK return the json
  • http://localhost:3000/api/files?filename=something.png -> Returns error 404 : Cannot GET /api/files
  • http://localhost:3000/api/files?filename=something.png&test=test -> OK return the json
  • http://localhost:3000/api/files?filename=something.png with header Accept: text/html -> OK return the json
  • http://localhost:3000/api/files?filename=anything inside an img src (because of header Sec-Fetch-Dest: image ?) -> Returns error 404 : Cannot GET /api/files

This because a big issue for create routes for img src.

Complete minimal reproducer

https://github.com/Zareix/tan-start-repro

Steps to Reproduce the Bug

  1. Create a GET server route
  2. Call it with a searchParams that as a image file extension

Expected behavior

It should send request to the server route everytime

Screenshots or Videos

No response

Platform

  • Router / Start Version: 1.169.2
  • OS: macOS
  • Browser: Chrome
  • Browser Version: 148.0.7778.96
  • Bundler: vite (with bun)
  • Bundler Version: 8.0.11

Additional context

No response

Activity

  1. changed the title [-]File extension[/-] [+]File extension/Image src does not end to server route but 404[/+] on May 15, 2026
  2. schiller-manuel commented on May 15, 2026

    @schiller-manuel
    Collaborator

    i suspect this is a nitro issue

    cc @pi0

    @Zareix does this occur if you disable nitro?

  3. Zareix commented on May 15, 2026

    @Zareix
    Author

    i suspect this is a nitro issue

    cc @pi0

    @Zareix does this occur if you disable nitro?

    Indeed it works without nitro plugin

  4. pi0 commented on May 15, 2026

    @pi0
    Contributor

    Likely related to nitrojs/nitro#4252 (comment)

    I have to investigate it properly since it is 3rd time we are regressing on patches in this area. Sorry for inconviniences.

  5. Zareix commented on May 15, 2026

    @Zareix
    Author

    Ok thank you I'll track this issue
    Btw it seems to be only on dev server

  6. jantimon commented on May 19, 2026

    @jantimon

    We ran into the same issue with a TanStack Start + nitro/vite app: <img src="/api/v1/projects/:id/thumbnail"> returns 404 text/html in dev, but opening the same URL directly works fine. It looks like that the trigger is the Sec-Fetch-Dest: image header as the Sec-Fetch-Dest: empty header when using fetch works

    I tried nitro-nightly@3.0.1-20260519-181425-9cc59cf7, which includes #4272 ("fix(vite): route asset-extensioned URLs matching explicit routes to nitro") and the related 7d49dca ("route extensionless URLs matching a nitro route to nitro under asset sec-fetch-dest")

    Unfortunately those nightly fixes didn't help for my TanStack Start app

    The fixed nitroDevMiddlewarePre checkes for matching nitro.routing.routes

    As far as i can tell the nitro.routing.routes values come from scanHandlers, which only scans <srcDir>/api/ and <srcDir>/routes/

    However TanStack API routes live at src/routes/api/** and register via viteDevServer.middlewares.use(...)
    Therefore nitro.routing.routes holds only the SSR catch-all /** and isExplicitRoute is always false and every /api/v1/* request falls through to the Sec-Fetch-Dest classifier

    So https://github.com/Zareix/tan-start-repro is still broken even with nitro-nightly@3.0.1-20260519-181425-9cc59cf7

    Not sure who is to blame.. Tanstack and Nitro just follow their conventions..

    As a hacky workaround you can just handle all api routes explicitly with vite:

    import { runtimeDir as nitroRuntimeDir } from "nitro/meta";
    import { resolve as resolvePath } from "node:path";
    
    nitro({
      preset: "node-server",
      hooks: {
        "build:before"(nitro) {
          nitro.options.handlers.push({
            route: "/api/v1/**",
            handler: resolvePath(nitroRuntimeDir, "internal/vite/ssr-renderer"),
          });
        },
      },
    }),
  7. pi0 commented on May 20, 2026

    @pi0
    Contributor

    draft nitrojs/nitro#4274 (hoping we can find something more stable)

  8. jinl0ng commented on Jun 18, 2026

    @jinl0ng

    same here

  9. gustavo-bordin commented on Jun 24, 2026

    @gustavo-bordin

    same here

  10. dennisameling commented on Sep 16, 2026

    @dennisameling

    Confirming this is fixed by nitrojs/nitro#4467, which is now live in Nitro's nightly builds v3.0.260903-beta 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions