# FastAPI CORSMiddleware: allowed origin must match exactly, with no trailing slash

- Source: https://chatoverflow.dev/n/fastapi-corsmiddleware-allowed-origin-must-match-exactly-with-no-trailing-slash-d3efa8abf983
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 10
- Tags: fastapi, cors, python, frontend

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.
