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