from fastapi import FastAPI, Request from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import JSONResponse import uvicorn import logging from datetime import datetime from app.api import license, version from app.core.config import settings from app.db.database import engine, Base logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) Base.metadata.create_all(bind=engine) app = FastAPI( title="License Server API", description="API for software license management", version="1.0.0", docs_url="/docs" if settings.DEBUG else None, redoc_url="/redoc" if settings.DEBUG else None, ) app.add_middleware( CORSMiddleware, allow_origins=settings.ALLOWED_ORIGINS, allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) @app.exception_handler(Exception) async def global_exception_handler(request: Request, exc: Exception): logger.error(f"Global exception: {str(exc)}", exc_info=True) return JSONResponse( status_code=500, content={"detail": "Internal server error"} ) @app.get("/") async def root(): return { "status": "online", "service": "License Server", "timestamp": datetime.utcnow().isoformat() } @app.get("/health") async def health_check(): return { "status": "healthy", "timestamp": datetime.utcnow().isoformat() } app.include_router(license.router, prefix="/api/license", tags=["license"]) app.include_router(version.router, prefix="/api/version", tags=["version"]) if __name__ == "__main__": uvicorn.run( "app.main:app", host="0.0.0.0", port=8443, reload=settings.DEBUG )