Solution by Framework
Python FastAPI
main.py
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
app = FastAPI()
# CORS configuration
app.add_middleware(
CORSMiddleware,
allow_origins=[
"http://localhost:3000", # Development
"https://your-domain.com", # Production
],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)Node.js Express
server.js
const express = require('express');
const cors = require('cors');
const app = express();
// CORS configuration
app.use(cors({
origin: [
'http://localhost:3000',
'https://your-domain.com'
],
credentials: true
}));Security Warning
Do not use allow_origins=["*"] in production!
Only allow your actual frontend domain.
How to Verify the Fix
- Restart your backend server
- Open browser DevTools (F12) → Network tab
- Send the request again and check the Response Headers
- If the
Access-Control-Allow-Originheader is present, success!