File tree 2 files changed +76
-58
lines changed
2 files changed +76
-58
lines changed Original file line number Diff line number Diff line change 4
4
import fastapi
5
5
import modern_di_fastapi
6
6
from advanced_alchemy .exceptions import DuplicateKeyError
7
+ from fastapi .middleware .cors import CORSMiddleware
7
8
8
9
from app import exceptions , ioc
9
10
from app .api .decks import ROUTER
10
11
from app .settings import settings
11
12
12
13
14
+ ALLOWED_ORIGINS = [
15
+ "http://localhost:5173" ,
16
+ # YOUR ALLOWED ORIGINS HERE
17
+ ]
18
+
19
+
13
20
def include_routers (app : fastapi .FastAPI ) -> None :
14
21
app .include_router (ROUTER , prefix = "/api" )
15
22
@@ -27,6 +34,13 @@ def __init__(self) -> None:
27
34
DuplicateKeyError ,
28
35
exceptions .duplicate_key_error_handler , # type: ignore[arg-type]
29
36
)
37
+ self .app .add_middleware (
38
+ CORSMiddleware ,
39
+ allow_origins = ALLOWED_ORIGINS ,
40
+ allow_credentials = True ,
41
+ allow_methods = ["*" ],
42
+ allow_headers = ["*" ],
43
+ )
30
44
31
45
@contextlib .asynccontextmanager
32
46
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