30 lines
918 B
Python
30 lines
918 B
Python
from fastapi import FastAPI
|
|
from sqlalchemy.ext.asyncio import AsyncEngine
|
|
from contextlib import asynccontextmanager
|
|
from app.routers import auth, auctions # Assuming you have a router for auth logic
|
|
from app.database import engine
|
|
from app.models import Base
|
|
|
|
# Define a lifespan context manager to handle startup and shutdown events
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
# Run code before the app starts
|
|
async with engine.begin() as conn:
|
|
await conn.run_sync(Base.metadata.create_all)
|
|
|
|
# Yield control to run the app
|
|
yield
|
|
|
|
# Run code before the app shuts down (if needed)
|
|
await engine.dispose()
|
|
|
|
# Initialize the FastAPI app with the lifespan event handler
|
|
app = FastAPI(lifespan=lifespan)
|
|
|
|
# Register your API routes
|
|
app.include_router(auth.router)
|
|
app.include_router(auctions.router)
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
return {"message": "Hello World"} |