Repository navigation
Commit 30cbeae
fix(server): an unimplemented API route must 404, not return the SPA (#64)
MEASURED 2026-09-15 while previewing the card editor (#185485/#185506):
GET /iris/item/185442/share Accept: application/json
-> 200 <!doctype html>...
The route is not implemented. The UI handler is mounted as router.add("*", "/*"),
so everything no API router claimed lands on it and is answered with index.html.
For a browser NAVIGATION that is exactly right — the SPA owns its own paths and
index.html boots it. For an API call it is a lie with a real cost: the caller
asked for JSON and got a web page with a 200, so a route that does not exist is
indistinguishable from one that does.
What that cost, precisely: the client ran JSON.parse on the page, threw
`SyntaxError: Unexpected token '<', "<!doctype "... is not valid JSON`, and the
error boundary took down the ENTIRE session view. Not the one section that had no
backend — the whole app, needing a Restart. #185506 expected unwired sections to
read "Not connected"; nothing ever got far enough to render that, so the ticket's
own description of the symptom was wrong, and every section it lists would have
failed the same way as it was built.
Two rules, because either alone leaves a hole:
- a path under an API root never falls back, whatever the caller sends. No
static asset lives under /iris/, so this is unambiguous.
- any request that ASKED for JSON gets the 404 instead of index.html. This
catches fetches under roots nobody has added to the list yet, which is the
failure mode the list itself has.
The Accept rule is applied only at the FALLBACK, after the exact-file lookup. My
first cut checked it up front, which would have 404'd a real asset fetched with
Accept: application/json — a regression traded for a fix. An exact file is an
exact file whatever the header says; only the step that turns "no such path" into
"here is a web page, status 200" is refused.
Same hole fixed on the dev-proxy path, where vite also answers an unknown path
with index.html, judged on the response's content-type because upstream is the
only thing that knows whether the path was real.
Verified against a server built from this source, beside the unpatched one:
/iris/item/185442/share (json) before: 200 <!doctype after: 404 {"error":…}
/ (html) after: 200 <!doctype
Tests: 5, mutation-verified against a no-op guard. Two of them exist for what must
KEEP working — a browser navigation still gets the SPA, and a real asset is still
served whatever its Accept header says.
NOT verified: the end-to-end click-through. A server from this source would not
render the session I had open, so I never clicked a card on it. res.json() on
{"error":"Not Found"} cannot throw a SyntaxError, but that is reasoning, not a
measurement, and the two are not the same thing.
The shape, which is the transferable part: a catch-all that serves documents was
answering for an API surface, so "not built yet" and "working" returned the same
status and the same body. Same family as a 405 with no GET registered reading as
an empty field, and as #185493, where one address for an outcome was guarded and
another was not.
Claude-Session: https://claude.ai/code/session_01JwiqN8M84qimu1TjZGSsdQ
Co-authored-by: Claude Opus 5 <[email protected]>1 parent aacb307 commit 30cbeae
2 files changed
Lines changed: 109 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
55 | 73 | | |
56 | 74 | | |
57 | 75 | | |
| |||
65 | 83 | | |
66 | 84 | | |
67 | 85 | | |
| 86 | + | |
68 | 87 | | |
69 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
70 | 95 | | |
71 | 96 | | |
72 | 97 | | |
| |||
83 | 108 | | |
84 | 109 | | |
85 | 110 | | |
86 | | - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
87 | 133 | | |
88 | 134 | | |
89 | 135 | | |
| |||
93 | 139 | | |
94 | 140 | | |
95 | 141 | | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
96 | 149 | | |
97 | 150 | | |
98 | 151 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
0 commit comments