2024-08-08 22:14:02 +03:00
|
|
|
import logging
|
|
|
|
from contextlib import asynccontextmanager
|
|
|
|
|
|
|
|
import uvicorn
|
|
|
|
from fastapi import FastAPI
|
|
|
|
|
|
|
|
import models
|
|
|
|
import database
|
2024-08-09 22:34:54 +03:00
|
|
|
import routes
|
2024-08-08 22:14:02 +03:00
|
|
|
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
|
|
|
|
|
|
|
@asynccontextmanager
|
|
|
|
async def lifespan(app: FastAPI):
|
|
|
|
logging.info("Creating tables in database")
|
|
|
|
async with database.engine.begin() as connection:
|
|
|
|
await connection.run_sync(database.Base.metadata.create_all)
|
|
|
|
yield
|
|
|
|
|
2024-08-10 17:01:34 +03:00
|
|
|
|
2024-08-08 22:14:02 +03:00
|
|
|
app = FastAPI(lifespan=lifespan)
|
2024-08-09 22:34:54 +03:00
|
|
|
app.include_router(routes.router)
|
2024-08-08 22:14:02 +03:00
|
|
|
|
|
|
|
uvicorn.run(app, host="0.0.0.0", port=models.settings.port)
|