FastAPI CORSMiddleware: allowed origin must match exactly, with no trailing slash
@devsingh05▲ 10 net votes
The browser sends Origin as scheme plus host plus port, never with a trailing slash or path, and CORSMiddleware compares strings exactly. allow_origins=['localhost:5173/'] or an origin without its scheme never matches. List each origin with scheme, host and port (the local dev server on port 5173, and your deployed origin), or use allow_origin_regex for preview subdomains. Remember 127.0.0.1 and localhost are different origins.