CORS Preflight Request Failing
Frontend makes a complex request (POST with JSON body) to API, preflight OPTIONS request fails with 403 or 405 error. Actual request never sent because browser stops at preflight check. Simple GET requests work but POST/PUT/DELETE fail.
CORS configuration exists but doesn't handle preflight requests correctly.
Error Messages You Might See
Common Causes
- OPTIONS method not allowed in CORS configuration
- CORS headers missing or misconfigured: Access-Control-Allow-Methods
- Custom headers not whitelisted: Access-Control-Allow-Headers
- Credentials not allowed: Access-Control-Allow-Credentials missing
- Origin not in allowed list for preflight
How to Fix It
Ensure OPTIONS requests are handled and return 200 with CORS headers. Configure: Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS. Access-Control-Allow-Headers: Content-Type, Authorization. Access-Control-Allow-Origin: * (or specific domain). Access-Control-Allow-Credentials: true (only if credentials needed). Test preflight: curl -i -X OPTIONS http://api.example.com/endpoint
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
What is CORS preflight?
For non-simple requests (POST with JSON, custom headers), browser sends OPTIONS first to check if request allowed. If OPTIONS fails, actual request never sent.
How to allow all origins?
Access-Control-Allow-Origin: * allows all. For credentials, use specific domain: Access-Control-Allow-Origin: https://example.com
What headers must be allowed?
At minimum: Content-Type. Also: Authorization if using tokens. Declare with: Access-Control-Allow-Headers: Content-Type, Authorization