The deployed frontend on Render was unable to communicate with the backend API, resulting in CORS (Cross-Origin Resource Sharing) errors that prevented any API requests from succeeding.
The backend's CORS middleware configuration only allowed requests from:
https://hackquest-ai.mehttps://www.hackquest-ai.me
However, the frontend was deployed on Render at:
https://hackquest-ai-1.onrender.com
This URL mismatch caused the browser to block all requests due to CORS policy restrictions.
File: backend/app/main.py
Lines: 101-105
origins = [
"https://hackquest-ai.me",
"https://www.hackquest-ai.me",
]origins = [
"https://hackquest-ai.me",
"https://www.hackquest-ai.me",
"https://hackquest-ai-1.onrender.com", # Render deployed frontend
"http://localhost:5173", # Development environment
]File: frontend/.env.production
# Backend API Configuration (Render deployment)
VITE_API_URL=https://hackquest-ai-1.onrender.com
VITE_WS_URL=wss://hackquest-ai-1.onrender.comThis configuration is already correct and properly points to the Render backend.
┌─────────────────────────────────────────────────┐
│ PRODUCTION DEPLOYMENT (Render) │
├─────────────────────────────────────────────────┤
│ │
│ Frontend (Vite + React) │
│ https://hackquest-ai-1.onrender.com │
│ ↓ (API Requests) │
│ Backend (FastAPI) │
│ https://hackquest-ai-1.onrender.com │
│ ↓ (Database Queries) │
│ MongoDB Atlas (Cloud Database) │
│ │
└─────────────────────────────────────────────────┘
- VITE_API_URL:
https://hackquest-ai-1.onrender.com- Backend API base URL - VITE_WS_URL:
wss://hackquest-ai-1.onrender.com- WebSocket secure URL - VITE_ENV:
production - VITE_ENABLE_DEBUG:
false
- ENVIRONMENT:
production - DEBUG:
False - MONGODB_URL:
mongodb+srv://[user]:[password]@[cluster].mongodb.net/?retryWrites=true&w=majority&tls=true - MONGODB_DB:
hackquest
The backend now properly allows requests from multiple origins while maintaining security:
app.add_middleware(
CORSMiddleware,
allow_origins=origins, # Only specific domains
allow_credentials=True, # Allow cookies/auth headers
allow_methods=["*"], # All HTTP methods
allow_headers=["*"], # All headers
max_age=3600 # Cache CORS 1 hour
)✅ Not using allow_origins=["*"] - Insecure in production
✅ Explicitly lists only real frontend domains
✅ Allows credentials - Needed for authentication
✅ HTTPS/WSS only - All URLs use secure protocols
✅ Production debug disabled - DEBUG=False in production
- Open DevTools (F12) → Network tab
- Trigger an API call (e.g., login, fetch data)
- Expected: Request URL starts with
https://hackquest-ai-1.onrender.com/api/ - Check: No CORS errors in Console tab
curl https://hackquest-ai-1.onrender.com/api/healthExpected response:
{
"status": "healthy",
"service": "hackquest-ai-backend",
"version": "1.0.0",
"environment": "production",
"database": "connected"
}curl -H "Origin: https://hackquest-ai-1.onrender.com" \
-H "Access-Control-Request-Method: GET" \
https://hackquest-ai-1.onrender.com/api/health -vExpected response headers:
Access-Control-Allow-Origin: https://hackquest-ai-1.onrender.com
Commit Hash: See recent commits in this repository
Changes Made:
- ✅ Added
https://hackquest-ai-1.onrender.comto CORS allowed origins - ✅ Added
http://localhost:5173for local development support - ✅ Updated CORS logging to show configured origins
-
Clear browser cache
# Hard refresh in browser Ctrl+Shift+R (Windows/Linux) Cmd+Shift+R (Mac) -
Verify backend deployment
- Check Render dashboard logs for any startup errors
- Ensure CORS configuration was deployed (redeploy if needed)
-
Check frontend build
# Rebuild frontend with correct environment cd frontend npm run build # Verify dist/ contains correct API URL
-
Monitor logs
- Render Backend Logs: Watch for CORS middleware messages
- Browser Console: Check for detailed CORS error messages
- Network Tab: Inspect request/response headers
This fix ensures that the frontend and backend can communicate properly on Render's deployment platform by:
- ✅ Adding the Render frontend URL to the CORS allowed origins list
- ✅ Supporting local development with localhost
- ✅ Maintaining production security best practices
- ✅ Properly configuring environment variables in both applications
The integration is now complete and the frontend-backend communication should work seamlessly on Render.