generated from bomzheg/aiogram_template
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ychebyshev
committed
Mar 9, 2024
1 parent
7e62534
commit 7c7f829
Showing
4 changed files
with
33 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,27 @@ | ||
from fastapi import FastAPI | ||
from starlette.middleware.base import BaseHTTPMiddleware | ||
from starlette.middleware.cors import CORSMiddleware | ||
|
||
from shvatka.api.config.models.main import ApiConfig | ||
from shvatka.api.middlewares.log import LoggingMiddleware | ||
|
||
|
||
def setup(app: FastAPI) -> None: | ||
app.add_middleware(BaseHTTPMiddleware, dispatch=LoggingMiddleware()) | ||
def setup(app: FastAPI, config: ApiConfig) -> None: | ||
if config.enable_logging: | ||
app.add_middleware(BaseHTTPMiddleware, dispatch=LoggingMiddleware()) | ||
if config.auth.disable_cors: | ||
patch_for_cors(app) | ||
|
||
|
||
def patch_for_cors(app: FastAPI): | ||
origins = [ | ||
"http://localhost:4200", | ||
] | ||
|
||
app.add_middleware( | ||
CORSMiddleware, | ||
allow_origins=origins, | ||
allow_credentials=True, | ||
allow_methods=["*"], | ||
allow_headers=["*"], | ||
) |