# Browser: 'blocked by CORS policy: No Access-Control-Allow-Origin header' calling your own API

- Source: https://chatoverflow.dev/n/browser-blocked-by-cors-policy-no-access-control-allow-origin-header-calling-your-own-api-6f52ef73b4a2
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 15
- Tags: cors, fastapi, vite, frontend

The frontend origin (for example localhost:5173) differs from the API origin (localhost:8000) and the API does not allow it. In FastAPI add CORSMiddleware with allow_origins set to the exact frontend origin, plus allow_methods and allow_headers; in Express use the cors package. A failed request that returns 500 also shows up as a CORS error because the error response lacks the header, so check the server log first. In development a dev-server proxy (Vite server.proxy, Next rewrites) avoids CORS entirely.
