Spaces:
Runtime error
Runtime error
chih.yikuan commited on
Commit ·
9fdcfbc
1
Parent(s): 8f19122
Fix: Add test route and improve report-demo route with better error handling
Browse files- chatkit/backend/app/main.py +27 -4
chatkit/backend/app/main.py
CHANGED
|
@@ -239,6 +239,21 @@ async def health_check():
|
|
| 239 |
return {"status": "healthy", "service": "ClassLens"}
|
| 240 |
|
| 241 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
@app.get("/report-template.html")
|
| 243 |
async def serve_report_template():
|
| 244 |
"""Serve the report template HTML file."""
|
|
@@ -272,7 +287,7 @@ async def serve_report_demo():
|
|
| 272 |
possible_paths = [p for p in possible_paths if p is not None]
|
| 273 |
|
| 274 |
for template_path in possible_paths:
|
| 275 |
-
if template_path.exists():
|
| 276 |
return FileResponse(
|
| 277 |
template_path,
|
| 278 |
media_type="text/html",
|
|
@@ -283,8 +298,15 @@ async def serve_report_demo():
|
|
| 283 |
current_dir = base_dir
|
| 284 |
files_in_dir = list(current_dir.glob("*")) if current_dir.exists() else []
|
| 285 |
searched_paths = [str(p) for p in possible_paths]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
return Response(
|
| 287 |
-
content=f"Report template not found.\
|
| 288 |
status_code=404,
|
| 289 |
media_type="text/plain"
|
| 290 |
)
|
|
@@ -314,8 +336,9 @@ if STATIC_DIR.exists():
|
|
| 314 |
@app.get("/{full_path:path}")
|
| 315 |
async def serve_spa_routes(full_path: str):
|
| 316 |
"""Catch-all route to serve React SPA for client-side routing."""
|
| 317 |
-
# Don't serve SPA for API routes
|
| 318 |
-
|
|
|
|
| 319 |
return Response(status_code=404)
|
| 320 |
|
| 321 |
# Check if it's a static file
|
|
|
|
| 239 |
return {"status": "healthy", "service": "ClassLens"}
|
| 240 |
|
| 241 |
|
| 242 |
+
@app.get("/test-routes")
|
| 243 |
+
async def test_routes():
|
| 244 |
+
"""Test endpoint to verify routes are working."""
|
| 245 |
+
return {
|
| 246 |
+
"message": "Routes are working!",
|
| 247 |
+
"report_demo_route": "/report-demo",
|
| 248 |
+
"available_paths": [
|
| 249 |
+
"/health",
|
| 250 |
+
"/api/health",
|
| 251 |
+
"/report-demo",
|
| 252 |
+
"/test-routes"
|
| 253 |
+
]
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
|
| 257 |
@app.get("/report-template.html")
|
| 258 |
async def serve_report_template():
|
| 259 |
"""Serve the report template HTML file."""
|
|
|
|
| 287 |
possible_paths = [p for p in possible_paths if p is not None]
|
| 288 |
|
| 289 |
for template_path in possible_paths:
|
| 290 |
+
if template_path and template_path.exists():
|
| 291 |
return FileResponse(
|
| 292 |
template_path,
|
| 293 |
media_type="text/html",
|
|
|
|
| 298 |
current_dir = base_dir
|
| 299 |
files_in_dir = list(current_dir.glob("*")) if current_dir.exists() else []
|
| 300 |
searched_paths = [str(p) for p in possible_paths]
|
| 301 |
+
debug_info = {
|
| 302 |
+
"searched_paths": searched_paths,
|
| 303 |
+
"current_dir": str(current_dir),
|
| 304 |
+
"files_in_dir": [str(f.name) for f in files_in_dir[:10]],
|
| 305 |
+
"static_dir": str(STATIC_DIR) if STATIC_DIR.exists() else "does not exist",
|
| 306 |
+
"__file__": str(Path(__file__)),
|
| 307 |
+
}
|
| 308 |
return Response(
|
| 309 |
+
content=f"Report template not found.\nDebug info:\n{json.dumps(debug_info, indent=2)}",
|
| 310 |
status_code=404,
|
| 311 |
media_type="text/plain"
|
| 312 |
)
|
|
|
|
| 336 |
@app.get("/{full_path:path}")
|
| 337 |
async def serve_spa_routes(full_path: str):
|
| 338 |
"""Catch-all route to serve React SPA for client-side routing."""
|
| 339 |
+
# Don't serve SPA for API routes or specific endpoints
|
| 340 |
+
excluded_paths = ("api/", "auth/", "chatkit", "report-demo", "test-routes", "health")
|
| 341 |
+
if full_path.startswith(excluded_paths) or full_path in excluded_paths:
|
| 342 |
return Response(status_code=404)
|
| 343 |
|
| 344 |
# Check if it's a static file
|