"""FastAPI application entry point.""" import logging from contextlib import asynccontextmanager from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from app.api import api_router from app.config import get_settings from app.database import init_db from app.scheduler import start_scheduler, stop_scheduler # Configure logging logging.basicConfig( level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", ) logger = logging.getLogger(__name__) settings = get_settings() @asynccontextmanager async def lifespan(app: FastAPI): """Application lifespan handler.""" # Startup logger.info(f"Starting {settings.app_name}...") # Initialize database await init_db() logger.info("Database initialized") # Start scheduler start_scheduler() logger.info("Scheduler started") yield # Shutdown stop_scheduler() logger.info("Application shutdown complete") # Create FastAPI application app = FastAPI( title=settings.app_name, description="Domain availability monitoring service", version="1.0.0", lifespan=lifespan, ) # Configure CORS app.add_middleware( CORSMiddleware, allow_origins=[ "http://localhost:3000", "http://127.0.0.1:3000", "http://10.42.0.73:3000", # Add production origins here ], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # Include API routes app.include_router(api_router, prefix="/api/v1") @app.get("/") async def root(): """Root endpoint.""" return { "name": settings.app_name, "version": "1.0.0", "status": "running", } @app.get("/health") async def health_check(): """Health check endpoint.""" return {"status": "healthy"}