♻️ Include FRONTEND_HOST
in CORS origins by default (#1348)
This commit is contained in:

committed by
GitHub

parent
a292dbe10d
commit
e64c9100ec
@@ -38,6 +38,13 @@ class Settings(BaseSettings):
|
|||||||
list[AnyUrl] | str, BeforeValidator(parse_cors)
|
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
|
PROJECT_NAME: str
|
||||||
SENTRY_DSN: HttpUrl | None = None
|
SENTRY_DSN: HttpUrl | None = None
|
||||||
POSTGRES_SERVER: str
|
POSTGRES_SERVER: str
|
||||||
|
@@ -21,12 +21,10 @@ app = FastAPI(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Set all CORS enabled origins
|
# Set all CORS enabled origins
|
||||||
if settings.BACKEND_CORS_ORIGINS:
|
if settings.all_cors_origins:
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
allow_origins=[
|
allow_origins=settings.all_cors_origins,
|
||||||
str(origin).strip("/") for origin in settings.BACKEND_CORS_ORIGINS
|
|
||||||
],
|
|
||||||
allow_credentials=True,
|
allow_credentials=True,
|
||||||
allow_methods=["*"],
|
allow_methods=["*"],
|
||||||
allow_headers=["*"],
|
allow_headers=["*"],
|
||||||
|
Reference in New Issue
Block a user