from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from contextlib import asynccontextmanager import uvicorn from adapters.sqlite.database import init_db from routers import entities, export, data, amocrm from utils.config import settings @asynccontextmanager async def lifespan(app: FastAPI): # Startup await init_db() yield # Shutdown pass app = FastAPI( title="AMO CRM Data Collection Service", description="Service for collecting and exporting AMO CRM data to Google Sheets", version="0.1.0", lifespan=lifespan, ) # CORS middleware app.add_middleware( CORSMiddleware, allow_origins=["*"], # Configure appropriately for production allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # Include routers app.include_router(entities.router, prefix=f"{settings.API_V1_STR}/entities", tags=["entities"]) app.include_router(export.router, prefix=f"{settings.API_V1_STR}/export", tags=["export"]) app.include_router(data.router, prefix=f"{settings.API_V1_STR}/data", tags=["data"]) app.include_router(amocrm.router, prefix=f"{settings.API_V1_STR}/amocrm", tags=["amocrm"]) @app.get("/") async def root(): return {"message": "AMO CRM Data Collection Service", "version": "0.1.0"} @app.get("/health") async def health_check(): return {"status": "healthy"} if __name__ == "__main__": uvicorn.run( "app:app", host="0.0.0.0", port=8000, reload=True, log_level=settings.LOG_LEVEL.lower(), )