Browser Blocks the API Call
A page at https://app.example.com calls https://api.example.com/data with fetch(). The browser console shows a CORS error, but the same request with curl works. What fixes it?
https://app.example.com
https://api.example.com/data
fetch()
curl
Choose one answer
Add Access-Control-Allow-Origin: https://app.example.com to the API's responses.
Access-Control-Allow-Origin: https://app.example.com
Add mode: "no-cors" to the fetch call so the browser can read the response.
mode: "no-cors"
Add a firewall rule allowing the browser's IP address to reach the API.
Serve the page over HTTP instead of HTTPS so the origins are treated as equal.