Besjon Cifliku commited on
Commit
1710209
·
1 Parent(s): bf9e9a4

debug: why frontend files are not served

Browse files
Files changed (1) hide show
  1. server.py +23 -14
server.py CHANGED
@@ -767,22 +767,31 @@ def _serialize_analysis(analysis):
767
 
768
  _FRONTEND_DIR = BASE_DIR / "frontend" / "dist"
769
 
770
- if _FRONTEND_DIR.is_dir():
771
- from starlette.exceptions import HTTPException as _StarletteHTTPException
772
-
773
- class _SPAStaticFiles(StaticFiles):
774
- """StaticFiles with SPA fallback: unknown paths serve index.html."""
 
 
 
 
 
 
 
775
 
776
- async def get_response(self, path, scope):
777
- try:
778
- return await super().get_response(path, scope)
779
- except _StarletteHTTPException as e:
780
- if e.status_code == 404:
781
- return await super().get_response(".", scope)
782
- raise
783
 
784
- app.mount("/", _SPAStaticFiles(directory=str(_FRONTEND_DIR), html=True), name="frontend")
785
- logger.info("Mounted frontend from %s", _FRONTEND_DIR)
 
 
 
 
 
 
 
 
 
786
 
787
 
788
  if __name__ == "__main__":
 
767
 
768
  _FRONTEND_DIR = BASE_DIR / "frontend" / "dist"
769
 
770
+ @app.get("/api/debug/frontend")
771
+ async def debug_frontend_files():
772
+ """List all files in the frontend dist directory (for debugging deploys)."""
773
+ if not _FRONTEND_DIR.is_dir():
774
+ return {"exists": False, "path": str(_FRONTEND_DIR)}
775
+ files = []
776
+ for root, _dirs, filenames in os.walk(str(_FRONTEND_DIR)):
777
+ for f in filenames:
778
+ full = os.path.join(root, f)
779
+ rel = os.path.relpath(full, str(_FRONTEND_DIR))
780
+ files.append({"path": rel, "size": os.path.getsize(full)})
781
+ return {"exists": True, "path": str(_FRONTEND_DIR), "files": files}
782
 
 
 
 
 
 
 
 
783
 
784
+ if _FRONTEND_DIR.is_dir():
785
+ @app.get("/{full_path:path}")
786
+ async def serve_frontend(full_path: str):
787
+ """Serve the React SPA — static files or index.html fallback."""
788
+ if full_path:
789
+ file_path = (_FRONTEND_DIR / full_path).resolve()
790
+ if file_path.is_file() and file_path.is_relative_to(_FRONTEND_DIR):
791
+ return FileResponse(file_path)
792
+ return FileResponse(_FRONTEND_DIR / "index.html")
793
+
794
+ logger.info("Frontend serving enabled from %s", _FRONTEND_DIR)
795
 
796
 
797
  if __name__ == "__main__":