Skip to content

Commit 12d62a3

Browse files
feat(cors): read allowed origins from CORS_ORIGINS env var
Allows deployments (e.g. the infra chart) to configure CORS origins via a comma-separated CORS_ORIGINS env var instead of relying on the hardcoded list. Falls back to the previous defaults when unset.
1 parent a3e8000 commit 12d62a3

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/main.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import os
23
import re
34
import uuid
45
from collections.abc import Awaitable, Callable
@@ -168,9 +169,12 @@ async def lifespan(_: FastAPI):
168169
)
169170

170171
origins = [
171-
"http://localhost",
172-
"http://127.0.0.1:8000",
173-
"https://api.honcho.dev",
172+
origin.strip()
173+
for origin in os.getenv(
174+
"CORS_ORIGINS",
175+
"http://localhost,http://127.0.0.1:8000,https://api.honcho.dev",
176+
).split(",")
177+
if origin.strip()
174178
]
175179

176180
app.add_middleware(

0 commit comments

Comments
 (0)