Skip to content

Commit 1fd06e3

Browse files
committed
feat: added cors support
1 parent 58fdb74 commit 1fd06e3

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

app/config/settings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ class Settings(BaseSettings):
1212
)
1313
env: str = Field(default="development", json_schema_extra={"env": "APP_ENV"})
1414

15+
cors_allowed_origins: str = Field(
16+
default="", json_schema_extra={"env": "CORS_ALLOWED_ORIGINS"}
17+
)
18+
1519
# Keycloak / OIDC
1620
keycloak_host: str = Field(
1721
default=str("localhost"),

app/main.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from fastapi import FastAPI
2+
from fastapi.middleware.cors import CORSMiddleware
23

34
from app.middleware.correlation_id import add_correlation_id
45
from app.platforms.dispatcher import load_processing_platforms
@@ -18,6 +19,14 @@
1819
version="1.0.0",
1920
)
2021

22+
app.add_middleware(
23+
CORSMiddleware,
24+
allow_origins=settings.cors_allowed_origins.split(","),
25+
allow_credentials=True,
26+
allow_methods=["*"],
27+
allow_headers=["*"],
28+
)
29+
2130
app.middleware("http")(add_correlation_id)
2231

2332
# include routers

env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ APP_HOST=0.0.0.0
99
APP_PORT=8000
1010
APP_ENV=development
1111

12+
# CORS
13+
CORS_ALLOWED_ORIGINS=http://localhost:5173
14+
15+
1216
# Database
1317
DATABASE_URL=
1418

0 commit comments

Comments
 (0)