from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from contextlib import asynccontextmanager import uvicorn from app.core.config import settings from app.core.database import connect_to_mongo, close_mongo_connection from app.api import keywords, pipelines, users, applications, monitoring @asynccontextmanager async def lifespan(app: FastAPI): # Startup await connect_to_mongo() yield # Shutdown await close_mongo_connection() app = FastAPI( title="News Engine Console API", description="뉴스 파이프라인 관리 및 모니터링 시스템", version="1.0.0", lifespan=lifespan ) # CORS app.add_middleware( CORSMiddleware, allow_origins=settings.ALLOWED_ORIGINS, allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # Health check @app.get("/health") async def health_check(): return {"status": "healthy", "service": settings.SERVICE_NAME} # Include routers app.include_router(keywords.router, prefix=f"{settings.API_V1_STR}/keywords", tags=["Keywords"]) app.include_router(pipelines.router, prefix=f"{settings.API_V1_STR}/pipelines", tags=["Pipelines"]) app.include_router(users.router, prefix=f"{settings.API_V1_STR}/users", tags=["Users"]) app.include_router(applications.router, prefix=f"{settings.API_V1_STR}/applications", tags=["Applications"]) app.include_router(monitoring.router, prefix=f"{settings.API_V1_STR}/monitoring", tags=["Monitoring"]) if __name__ == "__main__": uvicorn.run( "main:app", host="0.0.0.0", port=settings.PORT, reload=True )