Skip to content

Commit f6cfecb

Browse files
committed
fix: parse comma-separated CORS origins, strip trailing slash from API URL
1 parent 2c667e5 commit f6cfecb

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

apps/api/app/config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from pydantic import field_validator
12
from pydantic_settings import BaseSettings
23

34

@@ -9,5 +10,12 @@ class Settings(BaseSettings):
910

1011
model_config = {"env_file": ".env", "env_file_encoding": "utf-8"}
1112

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+
1220

1321
settings = Settings()

apps/web/lib/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {
1111
SummarizeResponse,
1212
} from "@/types/api"
1313

14-
const BASE_URL = process.env.NEXT_PUBLIC_API_URL ?? "http://localhost:8000"
14+
const BASE_URL = (process.env.NEXT_PUBLIC_API_URL ?? "http://localhost:8000").replace(/\/$/, "")
1515

1616
async function request<T>(path: string, options?: RequestInit): Promise<T> {
1717
const res = await fetch(`${BASE_URL}${path}`, {

0 commit comments

Comments
 (0)