From 06785908e1e62527c3d9301a6ee8ff2249aa9b40 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 10 Feb 2026 00:49:52 +0000 Subject: [PATCH] Return 404 when static fallback index is missing Co-authored-by: Theo Browne --- apps/t3/src/cli.test.ts | 8 ++++++++ apps/t3/src/cli.ts | 13 +++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/apps/t3/src/cli.test.ts b/apps/t3/src/cli.test.ts index 1fcfc4bbc8..5eaa3cead2 100644 --- a/apps/t3/src/cli.test.ts +++ b/apps/t3/src/cli.test.ts @@ -404,4 +404,12 @@ describe("resolveStaticAssetReadTarget", () => { kind: "forbidden", }); }); + + it("returns not_found when spa fallback file is missing", () => { + const tempDir = mkdtempSync(path.join(os.tmpdir(), "t3-static-missing-index-")); + const result = resolveStaticAssetReadTarget("/missing.js", tempDir); + expect(result).toEqual({ + kind: "not_found", + }); + }); }); diff --git a/apps/t3/src/cli.ts b/apps/t3/src/cli.ts index 4531a0c955..6decc18860 100644 --- a/apps/t3/src/cli.ts +++ b/apps/t3/src/cli.ts @@ -433,7 +433,11 @@ export function resolveStaticAssetReadTarget( requestUrl: string | undefined, distRoot: string, resolvedRealDistRoot?: string, -): { kind: "file"; filePath: string } | { kind: "forbidden" } | { kind: "bad_request" } { +): + | { kind: "file"; filePath: string } + | { kind: "forbidden" } + | { kind: "bad_request" } + | { kind: "not_found" } { const normalizedDistRoot = path.resolve(distRoot); const realDistRoot = resolvedRealDistRoot ?? @@ -461,7 +465,7 @@ export function resolveStaticAssetReadTarget( const indexPath = path.join(normalizedDistRoot, "index.html"); const indexFile = resolveSafeFilePathInDist(indexPath, realDistRoot); if (indexFile.kind !== "file") { - return { kind: "bad_request" }; + return indexFile.kind === "forbidden" ? { kind: "forbidden" } : { kind: "not_found" }; } return indexFile; @@ -494,6 +498,11 @@ function startStaticWebServer(distRoot: string, port: number) { response.end("Forbidden"); return; } + if (resolvedPath.kind === "not_found") { + response.statusCode = 404; + response.end("Not found"); + return; + } const targetPath = resolvedPath.filePath; fs.readFile(targetPath, (error, content) => {