File tree Expand file tree Collapse file tree 2 files changed +76
-58
lines changed Expand file tree Collapse file tree 2 files changed +76
-58
lines changed Original file line number Diff line number Diff line change 44import fastapi
55import modern_di_fastapi
66from advanced_alchemy .exceptions import DuplicateKeyError
7+ from fastapi .middleware .cors import CORSMiddleware
78
89from app import exceptions , ioc
910from app .api .decks import ROUTER
1011from app .settings import settings
1112
1213
14+ ALLOWED_ORIGINS = [
15+ "http://localhost:5173" ,
16+ # YOUR ALLOWED ORIGINS HERE
17+ ]
18+
19+
1320def include_routers (app : fastapi .FastAPI ) -> None :
1421 app .include_router (ROUTER , prefix = "/api" )
1522
@@ -27,6 +34,13 @@ def __init__(self) -> None:
2734 DuplicateKeyError ,
2835 exceptions .duplicate_key_error_handler , # type: ignore[arg-type]
2936 )
37+ self .app .add_middleware (
38+ CORSMiddleware ,
39+ allow_origins = ALLOWED_ORIGINS ,
40+ allow_credentials = True ,
41+ allow_methods = ["*" ],
42+ allow_headers = ["*" ],
43+ )
3044
3145 @contextlib .asynccontextmanager
3246 async def lifespan_manager (self , _ : fastapi .FastAPI ) -> typing .AsyncIterator [dict [str , typing .Any ]]:
You can’t perform that action at this time.
0 commit comments