-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
34 lines (27 loc) · 824 Bytes
/
main.py
File metadata and controls
34 lines (27 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from fastapi import FastAPI
from contextlib import asynccontextmanager
from config.models.base import Base
from config.database import db_connection
from api_v1 import register_routers
from app_includes import (
register_errors,
register_middlewares,
register_prometheus,
)
def start_app() -> FastAPI:
"""
Создание приложения со всеми настройками
"""
app = FastAPI(lifespan=lifespan)
register_routers(app=app)
register_errors(app=app)
register_middlewares(app=app)
register_prometheus(app=app)
return app
@asynccontextmanager
async def lifespan(app: FastAPI):
async with db_connection.engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
yield
await db_connection.dispose()
app = start_app()