Troubleshooting CORS Issues in Production¶
This guide helps you resolve CORS (Cross-Origin Resource Sharing) issues in the production environment.
Common CORS Issues¶
CORS errors typically occur when:
- The frontend container makes requests to the backend container
- The backend's CORS configuration doesn't match the origin of the requests
- Docker networking issues prevent proper communication between containers
Quick Fix Steps¶
-
Check your
.env.productionfile: -
Ensure
BACKEND_CORS_ORIGINSincludes all necessary origins -
For local development with Docker, include:
-
Configure correct API URL in your frontend:
-
Inside Docker network: Use
http://fastapi_rbac:8000 - From host browser: Use
http://localhost:8000 -
In react-frontend's docker-compose.prod.yml:
-
Test with the provided scripts:
```powershell # Test both containers together .\scripts\docker\test-cors-setup.ps1
# Diagnose specific CORS issues .\scripts\docker\diagnose-cors.ps1 ```
Advanced Troubleshooting¶
- Check browser console for specific CORS error messages
- Verify containers are on the same Docker network
- Test direct communication between containers using
curl - Look for CORS configuration logs in the backend container
Debugging Tools¶
docker-compose.prod-test.yml: Runs frontend and backend togetherscripts\docker\test-cors-setup.ps1: Sets up and tests the containersscripts\docker\diagnose-cors.ps1: Provides detailed diagnostic information
For persistent issues, check the container logs: