Repository navigation
Open
nitrojs/nitro
#4467Labels
Description
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 jsonhttp://localhost:3000/api/files?filename=something.png-> Returns error 404 : Cannot GET /api/fileshttp://localhost:3000/api/files?filename=something.png&test=test-> OK return the jsonhttp://localhost:3000/api/files?filename=something.pngwith headerAccept: text/html-> OK return the jsonhttp://localhost:3000/api/files?filename=anythinginside an img src (because of headerSec-Fetch-Dest: image?) -> Returns error 404 : Cannot GET /api/files
This because a big issue for create routes for img src.
Complete minimal reproducer
Steps to Reproduce the Bug
- Create a GET server route
- 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
Reacted by Dennis Ameling, Deniz Abdurrahmani, Niclas do, Abraham Schilling, Saullo Bretas Silva and Danny Lin
Activity
[-]File extension[/-][+]File extension/Image src does not end to server route but 404[/+]schiller-manuel commentedon May 15, 2026
i suspect this is a nitro issue
cc @pi0
@Zareix does this occur if you disable nitro?
Zareix commentedon May 15, 2026
Indeed it works without nitro plugin
pi0 commentedon May 15, 2026
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.
Zareix commentedon May 15, 2026
Ok thank you I'll track this issue
Btw it seems to be only on dev server
jantimon commentedon May 19, 2026
We ran into the same issue with a TanStack Start +
nitro/viteapp:<img src="/api/v1/projects/:id/thumbnail">returns404 text/htmlin dev, but opening the same URL directly works fine. It looks like that the trigger is theSec-Fetch-Dest: imageheader as theSec-Fetch-Dest: emptyheader when using fetch worksI tried
[email protected], which includes #4272 ("fix(vite): route asset-extensioned URLs matching explicit routes to nitro") and the related7d49dca("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
nitroDevMiddlewarePrecheckes for matchingnitro.routing.routesAs far as i can tell the
nitro.routing.routesvalues come fromscanHandlers, which only scans<srcDir>/api/and<srcDir>/routes/However TanStack API routes live at
src/routes/api/**and register viaviteDevServer.middlewares.use(...)Therefore
nitro.routing.routesholds only the SSR catch-all/**andisExplicitRouteis alwaysfalseand every/api/v1/*request falls through to theSec-Fetch-DestclassifierSo https://github.com/Zareix/tan-start-repro is still broken even with
[email protected]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:
pi0 commentedon May 20, 2026
draft nitrojs/nitro#4274 (hoping we can find something more stable)
jinl0ng commentedon Jun 18, 2026
same here
gustavo-bordin commentedon Jun 24, 2026
same here
perf(covers): optimize cover load & caching
fix(vite): only treat html responses as catch-all swallows
dennisameling commentedon Sep 16, 2026
Confirming this is fixed by nitrojs/nitro#4467, which is now live in
Nitro's nightly buildsv3.0.260903-beta 🚀