52 lines
1.3 KiB
Python
52 lines
1.3 KiB
Python
"""LetsBe Hub - Central licensing and telemetry service."""
|
|
|
|
import logging
|
|
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app import __version__
|
|
from app.config import settings
|
|
from app.db import engine
|
|
from app.routes import activation_router, admin_router, health_router, telemetry_router
|
|
|
|
# Configure logging
|
|
logging.basicConfig(
|
|
level=logging.DEBUG if settings.DEBUG else logging.INFO,
|
|
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
|
)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
"""Application lifespan handler."""
|
|
logger.info(f"Starting LetsBe Hub v{__version__}")
|
|
yield
|
|
logger.info("Shutting down LetsBe Hub")
|
|
await engine.dispose()
|
|
|
|
|
|
app = FastAPI(
|
|
title="LetsBe Hub",
|
|
description="Central licensing and telemetry service for LetsBe Cloud",
|
|
version=__version__,
|
|
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(health_router)
|
|
app.include_router(admin_router)
|
|
app.include_router(activation_router)
|
|
app.include_router(telemetry_router)
|