Skip to content

Commit d5298e3

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 c799a2c commit d5298e3

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
import time
@@ -169,9 +170,12 @@ async def lifespan(_: FastAPI):
169170
)
170171

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

177181
app.add_middleware(

0 commit comments

Comments
 (0)