File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,4 +14,6 @@ DB_PORT=5432
1414RMQ_HOST = rabbitmq
1515RMQ_PORT = 5672
1616RABBITMQ_DEFAULT_USER = guest
17- RABBITMQ_DEFAULT_PASS = guest
17+ RABBITMQ_DEFAULT_PASS = guest
18+ # ==================ORIGINS==================
19+ CURRENT_ORIGIN = http://locahost:8080
Original file line number Diff line number Diff line change 11from fastapi import FastAPI
22
33from config import settings
4- from api_v1 .users .views import router
4+ from api_v1 .users .views import router as users
55
66
77def register_routers (app : FastAPI ) -> None :
88 app .include_router (
9- router = router ,
9+ router = users ,
1010 prefix = settings .API_PREFIX ,
1111 )
Original file line number Diff line number Diff line change 11from .logs_errors import register_errors
2+ from .middlewares import register_middlewares
23
34
4- __all__ = ('register_errors' ,)
5+ __all__ = ('register_errors' ,
6+ 'register_middlewares' ,
7+ )
Original file line number Diff line number Diff line change 1+ from fastapi .middleware .cors import CORSMiddleware
2+ from fastapi import FastAPI
3+
4+ from config import settings
5+
6+
7+ def register_middlewares (app : FastAPI ) -> None :
8+ """
9+ Регистрация middleware
10+ """
11+ app .add_middleware (
12+ CORSMiddleware ,
13+ allow_origins = [
14+ settings .CURRENT_ORIGIN ,
15+ ],
16+ allow_credentials = True ,
17+ allow_methods = ['*' ],
18+ allow_headers = ['*' ],
19+ )
Original file line number Diff line number Diff line change @@ -54,6 +54,7 @@ class Settings(BaseSettings):
5454 API_PREFIX : str = '/api/v1'
5555 BASE_DIR : Path = base_dir
5656 LOG_DIR : Path = log_dir
57+ CURRENT_ORIGIN : str = config ('CURRENT_ORIGIN' )
5758
5859
5960settings = Settings ()
Original file line number Diff line number Diff line change 33
44from config import db_connection , BaseModel
55from api_v1 import register_routers
6- from app_includes import register_errors
6+ from app_includes import register_errors , register_middlewares
77
88
99
@@ -14,6 +14,7 @@ def start_app() -> FastAPI:
1414 app = FastAPI (lifespan = lifespan )
1515 register_routers (app = app )
1616 register_errors (app = app )
17+ register_middlewares (app = app )
1718 return app
1819
1920
You can’t perform that action at this time.
0 commit comments