API working in Postman but failing in the browser?
Seeing
CORS errorin DevTools?Don't randomly add
Access-Control-Allow-Origin: *.Use this checklist to find the actual problem.
CORS = Cross-Origin Resource Sharing
CORS is a browser-enforced mechanism that allows a server to specify which origins are permitted to access its resources from browser-based JavaScript.
The browser uses CORS headers to decide whether a cross-origin response can be exposed to frontend JavaScript. (MDN Web Docs)
Frontend
β
β Request
βΌ
βββββββββββββββββββ
β BROWSER β
β CORS CHECK β
ββββββββββ¬βββββββββ
β
βΌ
API SERVER
Think of the browser as a security checkpoint.
The server has to tell the browser:
"Yes, this origin is allowed to access my response."
An origin consists of:
PROTOCOL + DOMAIN + PORT
Example:
<https://app.example.com:3000>
| Component | Example |
|---|---|
| Protocol | https |
| Domain | app.example.com |
| Port | 3000 |