25 lines
641 B
Python
25 lines
641 B
Python
from fastapi.middleware.cors import CORSMiddleware
|
|
import os
|
|
|
|
def setup_cors(app):
|
|
origins = [
|
|
"http://localhost",
|
|
"http://localhost:80",
|
|
"http://localhost:3000",
|
|
"http://frontend:80",
|
|
]
|
|
|
|
# Add environment variable if set
|
|
allowed_origins = os.getenv("ALLOWED_ORIGINS", "")
|
|
if allowed_origins:
|
|
origins.extend([origin.strip() for origin in allowed_origins.split(",")])
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=origins,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
expose_headers=["*"],
|
|
)
|