@@ -6,6 +6,7 @@ import { promises as fs } from "node:fs";
66import path from "node:path" ;
77
88import { apiRoutes } from "./api/v1/routes" ;
9+ import { shouldReturnNotFoundForMissingStaticPath } from "./staticPaths" ;
910import { parsePort } from "./utils/env" ;
1011
1112const app = new Hono ( ) ;
@@ -27,21 +28,15 @@ const STATIC_ROOT = process.env.STATIC_ROOT ?? "./dist";
2728// Serve the built SPA (hashed assets, favicons, llms.txt, etc.).
2829app . use ( "/*" , serveStatic ( { root : STATIC_ROOT } ) ) ;
2930
30- // If a *root-level* static-document URL (`/llms.txt`, `/robots.txt`,
31- // `/manifest.json`, …) reaches this point, `serveStatic` already
31+ // If a static-looking URL reaches this point, `serveStatic` already
3232// couldn't match it, so return 404 instead of falling through to the
33- // SPA shell. Otherwise a typo at `/llm.txt` would render `index.html`,
34- // React Router's `:orgSlug` route would match the typo as a slug, and
35- // the user (or a bot) would see "Organization not found" with a 200
36- // status code — wrong for humans and doubly wrong for crawlers.
37- //
38- // Scope is deliberately narrow: only single-segment paths at the
39- // site root. Hashed build assets under `/assets/*.json` (i18n, chunks)
40- // and nested paths still fall through to the SPA handler below.
41- const ROOT_STATIC_DOC =
42- / ^ \/ [ a - z 0 - 9 . _ - ] + \. ( t x t | x m l | j s o n | p d f | c s v | y a m l | y m l | m d | w e b m a n i f e s t ) $ / i;
33+ // SPA shell. This covers root documents (`/llms.txt`), favicons, and
34+ // hashed Vite assets (`/assets/index-*.js`). Falling back to
35+ // `index.html` for a missing asset gives browsers the wrong MIME type
36+ // and makes Sentry source-context fetches display the HTML shell as
37+ // the suspect source.
4338app . get ( "*" , async ( c , next ) => {
44- if ( ROOT_STATIC_DOC . test ( c . req . path ) ) {
39+ if ( shouldReturnNotFoundForMissingStaticPath ( c . req . path ) ) {
4540 return c . notFound ( ) ;
4641 }
4742 return next ( ) ;
0 commit comments