CORS
Part of the Web course
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. ...
Want to learn Web CORS in a real environment?
Click below, get a fresh Linux box with Web ready to go, and work through CORS hands-on with an AI tutor that knows your code.
Start this lessonCORSWhat you'll learn
- Same-origin policy
- Origin
- Preflight OPTIONS
- Access-Control-Allow-Origin
- Access-Control-Allow-Methods
- Access-Control-Allow-Headers
- Credentials mode
Read this lesson in your language
All lessons in this course
14 lessons- 1What Is The Web20 min
- 2HTTP vs HTTPS15 min
- 3Request and Response Anatomy30 min
- 4Cookies, Sessions, and Tokens25 min
- 5DNS Explained25 min
- 6TLS and Certificates30 min
- 7CORS30 min
- 8REST API Basics25 min
- 9WebSockets and SSE25 min
- 10Caching and CDNs25 min
- 11Security Headers25 min
- 12Rate Limiting and Throttling20 min
- 13Monitoring and Logging20 min
- 14Capstone: A Tiny Web Server40 min
