🌐 Fix CORS configuration for Synology deployment

- Add CORS_ORIGINS environment variable support in config.py
- Update main.py to properly parse CORS_ORIGINS (support both wildcard * and comma-separated URLs)
- Enable wildcard CORS for production deployment
- Fix Preflight CORS errors in browser

Resolves: CORS 400 Bad Request errors during API calls
Tested: Successfully deployed and working on Synology NAS
This commit is contained in:
Hyungi Ahn
2025-09-24 12:25:02 +09:00
parent 5b70657dab
commit 2ccdf8c411
2 changed files with 11 additions and 2 deletions

View File

@@ -34,10 +34,18 @@ app = FastAPI(
redoc_url="/redoc"
)
# CORS 설정
# CORS 설정 - 환경변수 처리
cors_origins = []
if settings.CORS_ORIGINS == "*":
cors_origins = ["*"]
else:
cors_origins = [origin.strip() for origin in settings.CORS_ORIGINS.split(",")]
logger.info(f"🌐 CORS Origins: {cors_origins}")
app.add_middleware(
CORSMiddleware,
allow_origins=settings.ALLOWED_ORIGINS,
allow_origins=cors_origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],