Browse Source

♻️ Include `FRONTEND_HOST` in CORS origins by default (#1348)

pull/13907/head
Sebastián Ramírez 11 months ago
committed by GitHub
parent
commit
e64c9100ec
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 7
      backend/app/core/config.py
  2. 6
      backend/app/main.py

7
backend/app/core/config.py

@ -38,6 +38,13 @@ class Settings(BaseSettings):
list[AnyUrl] | str, BeforeValidator(parse_cors)
] = []
@computed_field # type: ignore[prop-decorator]
@property
def all_cors_origins(self) -> list[str]:
return [str(origin).rstrip("/") for origin in self.BACKEND_CORS_ORIGINS] + [
self.FRONTEND_HOST
]
PROJECT_NAME: str
SENTRY_DSN: HttpUrl | None = None
POSTGRES_SERVER: str

6
backend/app/main.py

@ -21,12 +21,10 @@ app = FastAPI(
)
# Set all CORS enabled origins
if settings.BACKEND_CORS_ORIGINS:
if settings.all_cors_origins:
app.add_middleware(
CORSMiddleware,
allow_origins=[
str(origin).strip("/") for origin in settings.BACKEND_CORS_ORIGINS
],
allow_origins=settings.all_cors_origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],

Loading…
Cancel
Save