Is this your problem?
- The console shows "blocked by CORS policy: No Access-Control-Allow-Origin header is present"
- A fetch or XHR to an API or another domain fails, while the same URL works in the address bar
- It works locally but breaks in production, or the other way round, as the origin changes
- A "preflight" OPTIONS request fails before the real request is sent
- The data is there (the server responded) but your JavaScript cannot read it
What usually causes it
How to tell: Without an Access-Control-Allow-Origin header, the browser blocks your page from reading the response.
How to tell: The server allows a different origin (http vs https, www vs bare, or a different domain or port) than the one calling it.
How to tell: For some requests the browser sends an OPTIONS check first; if the server does not answer it correctly, the real request never runs.
How to tell: Sending cookies or auth with a wildcard origin is not allowed; the origin must be named exactly.
How to tell: An API not meant to be called from a browser will not send CORS headers for your site.
Before you touch anything
- Read the exact console message; it names the origin that was blocked and the header that was missing.
- Decide who owns the API: your own server (you can add headers) or a third party (you may need a proxy).
How to fix it, step by step
-
1
Confirm it is really CORS
The server responded but the browser blocked your script from reading it. The console names the missing Access-Control-Allow-Origin header. That is CORS, not the server being down.
-
2
Add the header on the API server
On the server that owns the API, send Access-Control-Allow-Origin with your exact site origin (https://yourdomain.com), not a guess. This is the correct fix.
-
3
Handle the preflight
If requests use custom headers or methods, answer the OPTIONS preflight with the allowed methods and headers, and a 200. Most frameworks have a CORS middleware that does this.
-
4
Match the origin exactly
The allowed origin must match scheme, domain and port exactly. https://site.com and https://www.site.com are different origins.
-
5
For credentials, name the origin
If you send cookies or auth, set Allow-Credentials to true and name the exact origin; a wildcard is not allowed with credentials.
-
6
If it is a third-party API, proxy it
If you do not control the API and it sends no CORS headers, call it from your own server (a small proxy endpoint) and have your page call your server instead.
Stop and get help if
- You do not control the API and cannot add a server-side proxy, so the call cannot be made safely from the browser.
- It is a production app and loosening CORS risks exposing the API to other sites.
- The error only appears for some users or routes and the origin handling is tangled.
Stop it happening again
- Set CORS deliberately on your APIs, allowing only the origins that should call them.
- Keep the allowed origins in config, and update them when the site domain changes.
- Never work around CORS by disabling browser security or using a wildcard with credentials.
- For third-party APIs, call them server-side, not straight from the browser.
Questions people ask
Is a CORS error a bug in my code?
Not usually. Your request is fine; the server did not say your site is allowed to read the response. The fix is the server headers.
Can I fix it in the browser?
Only for local testing, by disabling security, which you must never do in production or ask users to do. The real fix is on the server.
Why does it work in Postman but not the browser?
Tools like Postman and the address bar do not enforce CORS; only browsers do, to protect users. So the API can work there and still block your page.