Spaces:
Running
Running
Fix static serving erro
Browse files- Dockerfile +3 -0
- src-python/src/main.py +41 -2
Dockerfile
CHANGED
|
@@ -51,6 +51,9 @@ RUN uv sync
|
|
| 51 |
# Copy built frontend from previous stage with proper ownership
|
| 52 |
COPY --chown=user --from=frontend-builder /app/build $HOME/app/static-frontend
|
| 53 |
|
|
|
|
|
|
|
|
|
|
| 54 |
# Set working directory back to app root
|
| 55 |
WORKDIR $HOME/app
|
| 56 |
|
|
|
|
| 51 |
# Copy built frontend from previous stage with proper ownership
|
| 52 |
COPY --chown=user --from=frontend-builder /app/build $HOME/app/static-frontend
|
| 53 |
|
| 54 |
+
# Copy static assets (robot URDF files, meshes, etc.)
|
| 55 |
+
COPY --chown=user static/ $HOME/app/static/
|
| 56 |
+
|
| 57 |
# Set working directory back to app root
|
| 58 |
WORKDIR $HOME/app
|
| 59 |
|
src-python/src/main.py
CHANGED
|
@@ -87,6 +87,45 @@ if static_dir:
|
|
| 87 |
else:
|
| 88 |
logger.warning(f"⚠️ Static directory not found in any of: {static_dir_candidates}")
|
| 89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
def get_static_dir() -> str | None:
|
| 92 |
"""Get the static directory path"""
|
|
@@ -164,8 +203,8 @@ async def serve_app_assets(path: str):
|
|
| 164 |
@app.get("/{path:path}")
|
| 165 |
async def serve_spa_fallback(path: str):
|
| 166 |
"""Serve the frontend for client-side routing"""
|
| 167 |
-
# If it's an API or
|
| 168 |
-
if path.startswith(("api/", "ws/")):
|
| 169 |
raise HTTPException(status_code=404, detail="Not found")
|
| 170 |
|
| 171 |
# For all other paths, serve the index.html (SPA)
|
|
|
|
| 87 |
else:
|
| 88 |
logger.warning(f"⚠️ Static directory not found in any of: {static_dir_candidates}")
|
| 89 |
|
| 90 |
+
# Mount robot assets (URDF files, meshes, etc.)
|
| 91 |
+
robot_assets_candidates = [
|
| 92 |
+
os.path.join(
|
| 93 |
+
os.path.dirname(os.path.dirname(__file__)), "..", "..", "static"
|
| 94 |
+
), # From src-python/src
|
| 95 |
+
os.path.join(
|
| 96 |
+
os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "static"
|
| 97 |
+
), # From src-python
|
| 98 |
+
"/home/user/app/static", # HF Spaces absolute path
|
| 99 |
+
"static", # Relative to working directory
|
| 100 |
+
]
|
| 101 |
+
|
| 102 |
+
robot_assets_dir = None
|
| 103 |
+
for candidate in robot_assets_candidates:
|
| 104 |
+
if os.path.exists(candidate):
|
| 105 |
+
robot_assets_dir = candidate
|
| 106 |
+
break
|
| 107 |
+
|
| 108 |
+
if robot_assets_dir:
|
| 109 |
+
app.mount(
|
| 110 |
+
"/robots",
|
| 111 |
+
StaticFiles(directory=os.path.join(robot_assets_dir, "robots")),
|
| 112 |
+
name="robots",
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
# Mount individual favicon file properly
|
| 116 |
+
@app.get("/favicon.png")
|
| 117 |
+
async def get_favicon():
|
| 118 |
+
favicon_path = os.path.join(robot_assets_dir, "favicon.png")
|
| 119 |
+
if os.path.exists(favicon_path):
|
| 120 |
+
return FileResponse(favicon_path)
|
| 121 |
+
raise HTTPException(status_code=404, detail="Favicon not found")
|
| 122 |
+
|
| 123 |
+
logger.info(f"🤖 Serving robot assets from: {robot_assets_dir}")
|
| 124 |
+
else:
|
| 125 |
+
logger.warning(
|
| 126 |
+
f"⚠️ Robot assets directory not found in any of: {robot_assets_candidates}"
|
| 127 |
+
)
|
| 128 |
+
|
| 129 |
|
| 130 |
def get_static_dir() -> str | None:
|
| 131 |
"""Get the static directory path"""
|
|
|
|
| 203 |
@app.get("/{path:path}")
|
| 204 |
async def serve_spa_fallback(path: str):
|
| 205 |
"""Serve the frontend for client-side routing"""
|
| 206 |
+
# If it's an API, WebSocket, or static asset path, let it pass through to other handlers
|
| 207 |
+
if path.startswith(("api/", "ws/", "robots/", "_app/", "static/", "favicon")):
|
| 208 |
raise HTTPException(status_code=404, detail="Not found")
|
| 209 |
|
| 210 |
# For all other paths, serve the index.html (SPA)
|