-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
53 lines (43 loc) · 1.09 KB
/
main.py
File metadata and controls
53 lines (43 loc) · 1.09 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from __future__ import annotations
import logging
from contextlib import asynccontextmanager
from typing import TYPE_CHECKING
import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.api.v1.routes import api_v1_router
from app.config import settings
from app.core.db_manager import db_manager
from app.utils.constants import ALLOW_ORIGINS
if TYPE_CHECKING:
from collections.abc import AsyncGenerator
logging.basicConfig(
level=settings.logging.log_level_value,
format=settings.logging.log_format,
)
@asynccontextmanager
async def lifespan(app_: FastAPI) -> AsyncGenerator[None, None]:
# startup
yield
# shutdown
await db_manager.dispose()
app = FastAPI(
lifespan=lifespan,
)
app.include_router(
api_v1_router,
)
app.add_middleware(
CORSMiddleware,
allow_origins=ALLOW_ORIGINS,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
if __name__ == "__main__":
uvicorn.run(
"main:app",
host=settings.run.host,
port=settings.run.port,
reload=True,
)