28 lines
554 B
Python
28 lines
554 B
Python
# app/main.py
|
|
|
|
from fastapi import FastAPI
|
|
from contextlib import asynccontextmanager
|
|
from app.core.config import settings
|
|
from app.db.session import engine
|
|
from app.db.base import Base
|
|
from app.api.routes import router
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
|
|
Base.metadata.create_all(bind=engine)
|
|
yield
|
|
|
|
def create_app() -> FastAPI:
|
|
app = FastAPI(
|
|
title=settings.app_name,
|
|
debug=settings.debug,
|
|
)
|
|
|
|
app.include_router(router)
|
|
|
|
return app
|
|
|
|
app = create_app()
|
|
app.router.lifespan_context = lifespan |