Skip to content

Commit e64c910

Browse files
authored
♻️ Include FRONTEND_HOST in CORS origins by default (#1348)
1 parent a292dbe commit e64c910

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

backend/app/core/config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ class Settings(BaseSettings):
3838
list[AnyUrl] | str, BeforeValidator(parse_cors)
3939
] = []
4040

41+
@computed_field # type: ignore[prop-decorator]
42+
@property
43+
def all_cors_origins(self) -> list[str]:
44+
return [str(origin).rstrip("/") for origin in self.BACKEND_CORS_ORIGINS] + [
45+
self.FRONTEND_HOST
46+
]
47+
4148
PROJECT_NAME: str
4249
SENTRY_DSN: HttpUrl | None = None
4350
POSTGRES_SERVER: str

backend/app/main.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@ def custom_generate_unique_id(route: APIRoute) -> str:
2121
)
2222

2323
# Set all CORS enabled origins
24-
if settings.BACKEND_CORS_ORIGINS:
24+
if settings.all_cors_origins:
2525
app.add_middleware(
2626
CORSMiddleware,
27-
allow_origins=[
28-
str(origin).strip("/") for origin in settings.BACKEND_CORS_ORIGINS
29-
],
27+
allow_origins=settings.all_cors_origins,
3028
allow_credentials=True,
3129
allow_methods=["*"],
3230
allow_headers=["*"],

0 commit comments

Comments
 (0)