from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from contextlib import asynccontextmanager from app.db.session import engine from app.db.base import Base from app.routers import auth, items, health @asynccontextmanager async def lifespan(app: FastAPI): # Create database tables Base.metadata.create_all(bind=engine) yield app = FastAPI( title="REST API Service", description="A comprehensive REST API built with FastAPI and SQLite", version="1.0.0", lifespan=lifespan, openapi_url="/openapi.json" ) # Add CORS middleware app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # Include routers app.include_router(auth.router, prefix="/auth", tags=["authentication"]) app.include_router(items.router, prefix="/items", tags=["items"]) app.include_router(health.router, tags=["health"]) @app.get("/") async def root(): return { "title": "REST API Service", "documentation": "/docs", "health_check": "/health" } if __name__ == "__main__": import uvicorn uvicorn.run(app, host="0.0.0.0", port=8000)