CORS Error - Cross-Origin Request Blocked
API requests fail with CORS error: 'Access-Control-Allow-Origin header missing'. The browser blocks requests to a different domain.
Your frontend is on one domain and API on another, or localhost vs deployed URL.
Error Messages You Might See
Common Causes
- API doesn't include CORS headers in response
- API allow-origin header doesn't match request origin
- Credentials (cookies) sent without proper CORS config
- OPTIONS preflight request not handled
- Missing wildcard or specific origin in CORS config
How to Fix It
Add CORS headers to API: Response headers { 'Access-Control-Allow-Origin': '*' }
For credentials: 'Access-Control-Allow-Origin': 'https://your-domain.com' (not wildcard)
Include: 'Access-Control-Allow-Credentials': 'true'
Handle OPTIONS: if (request.method === 'OPTIONS') return new Response(null, { headers: corsHeaders })
Use middleware to apply CORS to all routes
Real developers can help you.
You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.
Get HelpFrequently Asked Questions
Should I use CORS wildcard '*'?
Only for public APIs. For APIs with credentials, specify exact domain
Do I need CORS for same domain?
No, CORS only applies to cross-origin (different domain/port/protocol)
What's a preflight request?
Browser sends OPTIONS request first for certain request types. Server must respond with CORS headers