From 7d1fa8913d823009a855d5ae25ceeaba180d78ad Mon Sep 17 00:00:00 2001 From: Michael SCHAL Date: Sun, 19 Jul 2026 11:01:43 +0200 Subject: [PATCH] fix(web): servir le favicon en production MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Le fallback SPA renvoyait index.html pour /favicon.svg : l'icône n'apparaissait jamais. Les fichiers statiques racine existants sont maintenant servis tels quels, le reste retombe sur index.html. Co-Authored-By: Claude Opus 4.8 --- backend/app/main.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/backend/app/main.py b/backend/app/main.py index 16aeaa2..fc416ab 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -106,6 +106,17 @@ if os.path.isdir(_STATIC_DIR): @app.get("/{full_path:path}") async def spa_fallback(full_path: str): - """Renvoie index.html pour toutes les routes (SPA React).""" - index = os.path.join(_STATIC_DIR, "index.html") - return FileResponse(index) + """Fichier statique racine s'il existe (favicon…), sinon index.html. + + Sans ce test, /favicon.svg recevait index.html : aucun favicon ne + s'affichait en production. + """ + static_root = os.path.abspath(_STATIC_DIR) + candidate = os.path.abspath(os.path.join(static_root, full_path)) + if ( + full_path + and candidate.startswith(static_root + os.sep) + and os.path.isfile(candidate) + ): + return FileResponse(candidate) + return FileResponse(os.path.join(static_root, "index.html"))