Files
MAIA/backend/main.py
2025-04-17 11:25:21 +02:00

26 lines
798 B
Python

# main.py
from contextlib import _AsyncGeneratorContextManager, asynccontextmanager
from typing import Any, Callable
from fastapi import FastAPI, Depends
from core.database import get_engine, Base
from modules import router
import logging
logging.getLogger('passlib').setLevel(logging.ERROR) # fix bc package logging is broken
# Create DB tables (remove in production; use migrations instead)
def lifespan_factory() -> Callable[[FastAPI], _AsyncGeneratorContextManager[Any]]:
@asynccontextmanager
async def lifespan(app: FastAPI):
Base.metadata.drop_all(bind=get_engine())
Base.metadata.create_all(bind=get_engine())
yield
return lifespan
lifespan = lifespan_factory()
app = FastAPI(lifespan=lifespan)
# Include module router
app.include_router(router)