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.api.websites import router as websites_router from app.api.alerts import router as alerts_router from app.services.scheduler import start_scheduler, stop_scheduler @asynccontextmanager async def lifespan(app: FastAPI): Base.metadata.create_all(bind=engine) start_scheduler() yield stop_scheduler() app = FastAPI( title="Website Update Alert Service", description="A FastAPI service that monitors websites for updates and sends alerts", version="1.0.0", lifespan=lifespan, docs_url="/docs", redoc_url="/redoc", openapi_url="/openapi.json" ) app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) app.include_router(websites_router) app.include_router(alerts_router) @app.get("/") async def root(): return { "title": "Website Update Alert Service", "description": "A service that monitors websites for updates and provides alerts", "documentation": "/docs", "health_check": "/health" } @app.get("/health") async def health_check(): return { "status": "healthy", "service": "Website Update Alert Service", "version": "1.0.0" } if __name__ == "__main__": import uvicorn uvicorn.run(app, host="0.0.0.0", port=8000)