Your frontend runs on localhost:3000, your API runs on localhost:8000, and the request that works perfectly in curl fails in the browser with a red console message about Access-Control-Allow-Origin. Nothing is broken. The browser is doing exactly what it was designed to do, and it is protecting your users from a genuine attack, and the fix is one response header on the server.
Browsers enforce a boundary called the same-origin policy: JavaScript loaded from one origin may not read responses from a different origin unless that origin explicitly permits it. ...
What you'll learn
- same-origin policy
- Origin
- Preflight OPTIONS
- Access-Control-Allow-Origin
- Access-Control-Allow-Methods
- Access-Control-Allow-Headers
- Credentials mode
Work through CORS
Sign in free and open the Web course. Work through the lesson, and ask the AI tutor when you get stuck.
Read this lesson in your language
Explore other courses
Claude from Zero to Mastery47 lessons, 8.4h
Vibe Coding: Fundamentals12 lessons, 4.5h
Prompt Engineering11 lessons, 6.2h
Python19 lessons, 9.3h
Git13 lessons, 5.9h
Docker13 lessons, 6.6h
Kubernetes14 lessons, 8h
TypeScript18 lessons, 7.7h
Go20 lessons, 12.3h
React17 lessons, 10.2h
Linux17 lessons, 8.5h
Ansible12 lessons, 6.1h
Bash12 lessons, 5.7h
Helm10 lessons, 5.4h
GitLab CI11 lessons, 5.8h
Jenkins11 lessons, 5.3h
PostgreSQL14 lessons, 7.6h
MySQL13 lessons, 6.8h
Vibe Coding12 lessons, 5.8h
Vibe Coding: Prototype to Production12 lessons, 5.5h
Vibe Coding: Multi-Agent Engineering12 lessons, 5.3h
Vibe Coding: Advanced Engineering12 lessons, 7.3h