Spaces:
Running on Zero
Running on Zero
Manoj Thapa commited on
Commit ·
f10cd51
1
Parent(s): 9d48730
Fix static file serving for root assets
Browse files- backend/main.py +8 -3
backend/main.py
CHANGED
|
@@ -301,10 +301,15 @@ if __name__ == "__main__":
|
|
| 301 |
# SPA Fallback (Must be at the bottom)
|
| 302 |
@app.get("/{full_path:path}")
|
| 303 |
async def serve_spa(full_path: str):
|
| 304 |
-
#
|
| 305 |
-
#
|
| 306 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 307 |
if os.path.exists("frontend_static/index.html"):
|
| 308 |
return FileResponse("frontend_static/index.html")
|
|
|
|
| 309 |
# If running locally without build, just return 404 or message
|
| 310 |
return {"message": "Backend running. Frontend not built (use npm run dev for local development)."}
|
|
|
|
| 301 |
# SPA Fallback (Must be at the bottom)
|
| 302 |
@app.get("/{full_path:path}")
|
| 303 |
async def serve_spa(full_path: str):
|
| 304 |
+
# Try to serve a specific static file if it exists in the build folder
|
| 305 |
+
# This comes AFTER specific API routes and /assets mount, so it catches root files like /manoj.png
|
| 306 |
+
file_path = f"frontend_static/{full_path}"
|
| 307 |
+
if os.path.exists(file_path) and os.path.isfile(file_path):
|
| 308 |
+
return FileResponse(file_path)
|
| 309 |
+
|
| 310 |
+
# Otherwise, fallback to index.html for React Router (SPA)
|
| 311 |
if os.path.exists("frontend_static/index.html"):
|
| 312 |
return FileResponse("frontend_static/index.html")
|
| 313 |
+
|
| 314 |
# If running locally without build, just return 404 or message
|
| 315 |
return {"message": "Backend running. Frontend not built (use npm run dev for local development)."}
|