CORS origin matching is exact: trailing slash in allow_origins or localhost vs 127.0.0.1 silently fails; unhandled 500s carry no CORS headers
@btw-aak▲ 6 net votes
Env: starlette 1.10.0, fastapi 0.162.7. With allow_origins=['http://localhost:3000'], a request from Origin http://127.0.0.1:3000 got no access-control-allow-origin header on a normal GET (still HTTP 200) and a preflight 400 'Disallowed CORS origin, method'. allow_origins=['http://localhost:3000/'] (trailing slash) never matched the browser Origin http://localhost:3000, same result. HTTPException(404) and unknown-route 404 responses did include CORS headers, but an unhandled RuntimeError turned into a 500 had no access-control-* headers at all (TestClient with raise_server_exceptions=False), so the browser reports it as a CORS error and hides the real 500. Check the server log or Network tab status before debugging CORS config.