Spaces:
Sleeping
Sleeping
fix
Browse files- backend/Odin.py +21 -6
backend/Odin.py
CHANGED
|
@@ -973,17 +973,32 @@ mimetypes.add_type("text/css", ".css")
|
|
| 973 |
mimetypes.add_type("image/svg+xml", ".svg")
|
| 974 |
mimetypes.add_type("image/png", ".png")
|
| 975 |
|
| 976 |
-
@app.
|
| 977 |
async def serve_spa(full_path: str):
|
| 978 |
dist = os.path.join(FRONTEND, "dist")
|
| 979 |
-
|
| 980 |
-
|
|
|
|
|
|
|
|
|
|
| 981 |
if os.path.isfile(file_path):
|
| 982 |
return FileResponse(file_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 983 |
return FileResponse(os.path.join(dist, "index.html"))
|
| 984 |
-
file_path = os.path.join(FRONTEND, full_path) if full_path else os.path.join(FRONTEND, "index.html")
|
| 985 |
-
if os.path.isfile(file_path):
|
| 986 |
-
return FileResponse(file_path)
|
| 987 |
return FileResponse(os.path.join(FRONTEND, "index.html"))
|
| 988 |
|
| 989 |
|
|
|
|
| 973 |
mimetypes.add_type("image/svg+xml", ".svg")
|
| 974 |
mimetypes.add_type("image/png", ".png")
|
| 975 |
|
| 976 |
+
@app.api_route("/{full_path:path}", methods=["GET", "HEAD"])
|
| 977 |
async def serve_spa(full_path: str):
|
| 978 |
dist = os.path.join(FRONTEND, "dist")
|
| 979 |
+
public = os.path.join(FRONTEND, "public")
|
| 980 |
+
|
| 981 |
+
# 1. Try dist directory first
|
| 982 |
+
if os.path.isdir(dist) and full_path:
|
| 983 |
+
file_path = os.path.join(dist, full_path)
|
| 984 |
if os.path.isfile(file_path):
|
| 985 |
return FileResponse(file_path)
|
| 986 |
+
|
| 987 |
+
# 2. Try frontend/public directory (source static assets)
|
| 988 |
+
if os.path.isdir(public) and full_path:
|
| 989 |
+
pub_path = os.path.join(public, full_path)
|
| 990 |
+
if os.path.isfile(pub_path):
|
| 991 |
+
return FileResponse(pub_path)
|
| 992 |
+
|
| 993 |
+
# 3. Try frontend root directory
|
| 994 |
+
if full_path:
|
| 995 |
+
fe_path = os.path.join(FRONTEND, full_path)
|
| 996 |
+
if os.path.isfile(fe_path):
|
| 997 |
+
return FileResponse(fe_path)
|
| 998 |
+
|
| 999 |
+
# 4. Fallback to index.html for SPA client-side routing
|
| 1000 |
+
if os.path.isdir(dist):
|
| 1001 |
return FileResponse(os.path.join(dist, "index.html"))
|
|
|
|
|
|
|
|
|
|
| 1002 |
return FileResponse(os.path.join(FRONTEND, "index.html"))
|
| 1003 |
|
| 1004 |
|