fix(cors): add API domain to CORS origins and improve instance error handling
- Add API base URL to CORS allowed origins alongside web base URL - Add CORS origin logging on startup for debugging - Wrap instance creation in try/except with detailed error logging - Return proper error message instead of raw 500 for instance creation failures This fixes CORS errors when the frontend makes cross-origin requests and provides better diagnostics for instance creation failures.
This commit is contained in:
@@ -38,9 +38,15 @@ settings = Settings()
|
||||
app = FastAPI(title="Headquarter API")
|
||||
|
||||
# Configure CORS - must be before other middleware
|
||||
# Build allowed origins list including web and api domains
|
||||
cors_origins = [settings.web_base_url]
|
||||
if settings.api_base_url != settings.web_base_url:
|
||||
cors_origins.append(settings.api_base_url)
|
||||
logger.info("CORS configured with origins: %s", cors_origins)
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=[settings.web_base_url],
|
||||
allow_origins=cors_origins,
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
|
||||
Reference in New Issue
Block a user