Spaces:
Sleeping
Sleeping
Update backend/app/main.py
Browse files- backend/app/main.py +28 -4
backend/app/main.py
CHANGED
|
@@ -222,23 +222,47 @@ if os.path.isdir(frontend_dir):
|
|
| 222 |
name="assets",
|
| 223 |
)
|
| 224 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
# Catch-all route to serve index.html for React Router
|
| 226 |
-
# This must be last so API routes are matched first
|
| 227 |
@app.get("/{full_path:path}")
|
| 228 |
async def serve_frontend(full_path: str):
|
| 229 |
"""
|
| 230 |
Serve React app for all non-API routes.
|
| 231 |
React Router will handle client-side routing.
|
| 232 |
"""
|
| 233 |
-
# Skip API routes, docs, and static
|
| 234 |
if (full_path.startswith("api/") or
|
| 235 |
full_path.startswith("docs") or
|
| 236 |
full_path.startswith("openapi.json") or
|
| 237 |
-
full_path.startswith("assets/")
|
|
|
|
| 238 |
from fastapi import HTTPException
|
| 239 |
raise HTTPException(status_code=404)
|
| 240 |
|
| 241 |
-
# Serve index.html for all other routes
|
| 242 |
from fastapi.responses import FileResponse
|
| 243 |
index_path = os.path.join(frontend_dir, "index.html")
|
| 244 |
if os.path.exists(index_path):
|
|
|
|
| 222 |
name="assets",
|
| 223 |
)
|
| 224 |
|
| 225 |
+
# Serve static files from root (logo.png, favicon.ico, etc.)
|
| 226 |
+
# Files in public/ directory are copied to dist/ root during Vite build
|
| 227 |
+
# These routes must be defined BEFORE the catch-all route
|
| 228 |
+
@app.get("/logo.png")
|
| 229 |
+
async def serve_logo():
|
| 230 |
+
"""Serve logo.png from frontend_dist root."""
|
| 231 |
+
from fastapi.responses import FileResponse
|
| 232 |
+
logo_path = os.path.join(frontend_dir, "logo.png")
|
| 233 |
+
if os.path.exists(logo_path):
|
| 234 |
+
return FileResponse(logo_path, media_type="image/png")
|
| 235 |
+
from fastapi import HTTPException
|
| 236 |
+
raise HTTPException(status_code=404)
|
| 237 |
+
|
| 238 |
+
@app.get("/favicon.ico")
|
| 239 |
+
async def serve_favicon():
|
| 240 |
+
"""Serve favicon.ico from frontend_dist root."""
|
| 241 |
+
from fastapi.responses import FileResponse
|
| 242 |
+
favicon_path = os.path.join(frontend_dir, "favicon.ico")
|
| 243 |
+
if os.path.exists(favicon_path):
|
| 244 |
+
return FileResponse(favicon_path, media_type="image/x-icon")
|
| 245 |
+
from fastapi import HTTPException
|
| 246 |
+
raise HTTPException(status_code=404)
|
| 247 |
+
|
| 248 |
# Catch-all route to serve index.html for React Router
|
| 249 |
+
# This must be last so API routes and static files are matched first
|
| 250 |
@app.get("/{full_path:path}")
|
| 251 |
async def serve_frontend(full_path: str):
|
| 252 |
"""
|
| 253 |
Serve React app for all non-API routes.
|
| 254 |
React Router will handle client-side routing.
|
| 255 |
"""
|
| 256 |
+
# Skip API routes, docs, static assets, and known static files
|
| 257 |
if (full_path.startswith("api/") or
|
| 258 |
full_path.startswith("docs") or
|
| 259 |
full_path.startswith("openapi.json") or
|
| 260 |
+
full_path.startswith("assets/") or
|
| 261 |
+
full_path in ["logo.png", "favicon.ico"]):
|
| 262 |
from fastapi import HTTPException
|
| 263 |
raise HTTPException(status_code=404)
|
| 264 |
|
| 265 |
+
# Serve index.html for all other routes (React Router will handle routing)
|
| 266 |
from fastapi.responses import FileResponse
|
| 267 |
index_path = os.path.join(frontend_dir, "index.html")
|
| 268 |
if os.path.exists(index_path):
|