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""" + +
+ + +Impossible de charger la documentation : {str(e)}
", + status_code=500 + ) + # --- ENDPOINTS API --- @app.get(