Skip to content

Commit 0efad83

Browse files
Clément VALENTINclaude
andcommitted
feat: rendre les servers Swagger dynamiques selon FRONTEND_URL
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent a1a187d commit 0efad83

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

apps/api/src/main.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,19 @@ async def lifespan(app: FastAPI):
6868
await enedis_adapter.close()
6969

7070

71+
def get_servers():
72+
"""Build servers list for OpenAPI based on configuration."""
73+
servers = [
74+
{"url": "/api", "description": "API via proxy (relative)"},
75+
]
76+
# Add production server if FRONTEND_URL is configured
77+
if settings.FRONTEND_URL and settings.FRONTEND_URL != "http://localhost:3000":
78+
servers.insert(0, {"url": f"{settings.FRONTEND_URL}/api", "description": "Production API"})
79+
# Add local dev server
80+
servers.append({"url": "http://localhost:8000", "description": "Backend direct (dev)"})
81+
return servers
82+
83+
7184
app = FastAPI(
7285
title="MyElectricalData API",
7386
description="API Gateway for Enedis data access",
@@ -76,10 +89,7 @@ async def lifespan(app: FastAPI):
7689
docs_url="/docs", # Use default docs
7790
root_path="/api",
7891
redoc_url="/redoc",
79-
servers=[
80-
{"url": "/api", "description": "API via proxy"},
81-
{"url": "http://localhost:8000", "description": "Backend direct"},
82-
],
92+
servers=get_servers(),
8393
swagger_ui_init_oauth={
8494
"clientId": "",
8595
"usePkceWithAuthorizationCodeGrant": False,

0 commit comments

Comments
 (0)