harry19s commited on
Commit
13d9548
·
1 Parent(s): 3e31f95

Home page

Browse files
Files changed (1) hide show
  1. server/app.py +12 -3
server/app.py CHANGED
@@ -41,7 +41,7 @@ from pathlib import Path
41
 
42
  from fastapi import HTTPException
43
  from fastapi.middleware.cors import CORSMiddleware
44
- from fastapi.responses import FileResponse, RedirectResponse
45
  from fastapi.openapi.utils import get_openapi
46
  from fastapi.staticfiles import StaticFiles
47
 
@@ -159,12 +159,21 @@ def serve_root_index():
159
 
160
  @app.get("/web", include_in_schema=False)
161
  def serve_web_index():
162
- return RedirectResponse(url="/")
 
 
 
163
 
164
 
165
  @app.get("/web/{full_path:path}", include_in_schema=False)
166
  def serve_web_app(full_path: str):
167
- return RedirectResponse(url=f"/{full_path}")
 
 
 
 
 
 
168
 
169
 
170
  @app.get("/{full_path:path}", include_in_schema=False)
 
41
 
42
  from fastapi import HTTPException
43
  from fastapi.middleware.cors import CORSMiddleware
44
+ from fastapi.responses import FileResponse
45
  from fastapi.openapi.utils import get_openapi
46
  from fastapi.staticfiles import StaticFiles
47
 
 
159
 
160
  @app.get("/web", include_in_schema=False)
161
  def serve_web_index():
162
+ index_path = frontend_dist / "index.html"
163
+ if not index_path.exists():
164
+ raise HTTPException(status_code=404, detail="Frontend build not found. Build /frontend first.")
165
+ return FileResponse(index_path)
166
 
167
 
168
  @app.get("/web/{full_path:path}", include_in_schema=False)
169
  def serve_web_app(full_path: str):
170
+ candidate = frontend_dist / full_path
171
+ index_path = frontend_dist / "index.html"
172
+ if candidate.exists() and candidate.is_file():
173
+ return FileResponse(candidate)
174
+ if index_path.exists():
175
+ return FileResponse(index_path)
176
+ raise HTTPException(status_code=404, detail="Frontend build not found. Build /frontend first.")
177
 
178
 
179
  @app.get("/{full_path:path}", include_in_schema=False)