48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
"""Application principale — GSPARC Mezzouna API."""
|
|
import logging
|
|
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI, Request
|
|
from fastapi.responses import RedirectResponse
|
|
from fastapi.staticfiles import StaticFiles
|
|
|
|
from app.auth import init_auth
|
|
from app.routes import api_router
|
|
from app.routes.auth_routes import router as auth_router
|
|
|
|
logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(name)s] %(levelname)s: %(message)s")
|
|
logger = logging.getLogger("gsparc")
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
"""Au démarrage : préchauffer le JWT Baserow."""
|
|
logger.info("🚀 Démarrage GSPARC Mezzouna API")
|
|
try:
|
|
from app.baserow import get_jwt
|
|
await get_jwt()
|
|
logger.info("✅ Connexion Baserow établie")
|
|
except Exception as e:
|
|
logger.warning(f"⚠️ Connexion Baserow différée : {e}")
|
|
yield
|
|
logger.info("👋 Arrêt GSPARC Mezzouna API")
|
|
|
|
|
|
app = FastAPI(
|
|
title="GSPARC Mezzouna — متابعة استهلاك الوقود",
|
|
version="1.0.0",
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
# Auth (session middleware)
|
|
init_auth(app)
|
|
|
|
# Routes
|
|
app.include_router(auth_router)
|
|
app.include_router(api_router)
|
|
|
|
# Redirection racine
|
|
@app.get("/health")
|
|
async def health():
|
|
return {"status": "ok", "app": "gsparc-mezzouna", "version": "1.0.0"}
|