From 3e6dbb5c765779637902330bdbd6ae68f0a766f1 Mon Sep 17 00:00:00 2001 From: Michael SCHAL Date: Wed, 27 May 2026 10:07:50 +0200 Subject: [PATCH] feat: serve beautiful interactive glassmorphic documentation at /doc and redirect root to doc --- server/app/main.py | 258 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 258 insertions(+) diff --git a/server/app/main.py b/server/app/main.py index 08039be..976f4da 100644 --- a/server/app/main.py +++ b/server/app/main.py @@ -1,10 +1,13 @@ from contextlib import asynccontextmanager from datetime import datetime +import json +import os from uuid import UUID from typing import List, Optional from fastapi import FastAPI, HTTPException, Depends, Security, status from fastapi.middleware.cors import CORSMiddleware from fastapi.security.api_key import APIKeyHeader +from fastapi.responses import HTMLResponse, RedirectResponse from sqlmodel import Session, select from app.config import settings @@ -53,6 +56,261 @@ app.add_middleware( allow_headers=["*"], ) +# --- DOCUMENTATION ET REDIRECTIONS --- + +@app.get("/", include_in_schema=False) +def redirect_root_to_doc(): + """Redirige les requêtes de la racine vers la page de documentation.""" + return RedirectResponse(url="/doc") + +@app.get("/doc", response_class=HTMLResponse, include_in_schema=False) +def get_html_documentation(): + """ + Sert une page HTML interactive et magnifiquement stylisée (Glassmorphism) + rendant le guide d'intégration pour Agent IA (README_AI_AGENT.md). + """ + try: + # Chemin relatif vers la racine du serveur (où se trouve le README) + readme_path = "README_AI_AGENT.md" + if not os.path.exists(readme_path): + # Essayer un autre chemin au cas où + readme_path = "/app/README_AI_AGENT.md" + + if not os.path.exists(readme_path): + raise FileNotFoundError("README_AI_AGENT.md introuvable.") + + with open(readme_path, "r", encoding="utf-8") as f: + markdown_content = f.read() + + escaped_content = json.dumps(markdown_content) + + html_template = f""" + + + + + Documentation TodoFlow API + + + + + + + +
+ +
Chargement de la documentation...
+
+ + +""" + return HTMLResponse(content=html_template, status_code=200) + except Exception as e: + return HTMLResponse( + content=f"

Erreur

Impossible de charger la documentation : {str(e)}

", + status_code=500 + ) + # --- ENDPOINTS API --- @app.get(