Skip to content

Commit 321ee8e

Browse files
committed
fix: store cors_origins as str to avoid pydantic-settings JSON parsing
1 parent a556159 commit 321ee8e

2 files changed

Lines changed: 2 additions & 10 deletions

File tree

apps/api/app/config.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
1-
from pydantic import field_validator
21
from pydantic_settings import BaseSettings
32

43

54
class Settings(BaseSettings):
65
supabase_url: str = ""
76
supabase_key: str = ""
87
resend_api_key: str = ""
9-
cors_origins: list[str] = ["http://localhost:3000"]
8+
cors_origins: str = "http://localhost:3000"
109

1110
model_config = {"env_file": ".env", "env_file_encoding": "utf-8"}
1211

13-
@field_validator("cors_origins", mode="before")
14-
@classmethod
15-
def parse_cors_origins(cls, v: object) -> list[str]:
16-
if isinstance(v, str):
17-
return [o.strip() for o in v.split(",") if o.strip()]
18-
return v # type: ignore[return-value]
19-
2012

2113
settings = Settings()

apps/api/app/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
app.add_middleware(
1414
CORSMiddleware,
15-
allow_origins=settings.cors_origins,
15+
allow_origins=[o.strip() for o in settings.cors_origins.split(",") if o.strip()],
1616
allow_credentials=True,
1717
allow_methods=["*"],
1818
allow_headers=["*"],

0 commit comments

Comments
 (0)