Commit 7cdcebc
fix(api): add Access-Control-Max-Age 86400 to CORS preflight (BUG-API-303)
Without Access-Control-Max-Age the browser re-issues an OPTIONS preflight
before every CORS request. An SPA making 5 cross-origin API calls fires
5 extra preflight roundtrips. 24h (86400) is the modern browsers' clamp
ceiling — Chrome caps at 2h, Firefox at 24h, Safari at 7d — so we ask
for the maximum standard value and let each browser apply its own clamp.
The dashboard SPA is the main beneficiary: every authed call from
instanode.dev → api.instanode.dev used to pay the preflight cost. After
this change cooperative browsers cache the preflight result for up to
2h (Chrome) / 24h (Firefox).
Coverage block:
Symptom: OPTIONS preflight responses missing Access-Control-Max-Age
Enumeration: rg -F "fiberCORS" internal/ — 1 emit site in router.go
Sites found: 1
Sites touched: 1
Coverage test: TestCORSPreflight_HasMaxAgeHeader (new file
cors_maxage_test.go) — drives an OPTIONS preflight
through a fiberCORS-mirrored config and asserts
Access-Control-Max-Age=86400 on the response. Fails
today before the router.go change.
Live verified: pending merge + auto-deploy + curl -X OPTIONS -H
"Origin: https://instanode.dev" -H "Access-Control-
Request-Method: POST" https://api.instanode.dev/api/v1/whoami
| grep access-control-max-age
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 19dcb5f commit 7cdcebc
2 files changed
Lines changed: 80 additions & 0 deletions
| 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 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
193 | 197 | | |
194 | 198 | | |
195 | 199 | | |
| |||
206 | 210 | | |
207 | 211 | | |
208 | 212 | | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
209 | 222 | | |
210 | 223 | | |
211 | 224 | | |
| |||
0 commit comments