Jon Taylor commited on
Commit
82d5975
1 Parent(s): ad5d266

fixed static files

Browse files
Files changed (1) hide show
  1. server.py +11 -11
server.py CHANGED
@@ -21,21 +21,21 @@ app.add_middleware(
21
  # Mount the static directory
22
  app.mount("/static", StaticFiles(directory="frontend/out", html=True), name="static")
23
 
24
- @app.get("/{path_name:path}")
25
  async def catch_all(path_name: str):
26
- # Default route for the root
27
  if path_name == "":
28
- path_name = "index"
 
 
29
 
30
- # Construct file path with .html extension
31
- file_path = Path("frontend/out") / f"{path_name}.html"
32
-
33
  if file_path.is_file():
34
- # Serve the .html file if it exists
35
- return FileResponse(file_path)
36
- else:
37
- # If the specific .html file does not exist, raise a 404 error
38
- raise HTTPException(status_code=404, detail="Item not found")
 
 
39
 
40
  # Run the application using Uvicorn
41
  if __name__ == "__main__":
 
21
  # Mount the static directory
22
  app.mount("/static", StaticFiles(directory="frontend/out", html=True), name="static")
23
 
24
+ @app.get("/{path_name:path}", response_class=FileResponse)
25
  async def catch_all(path_name: str):
 
26
  if path_name == "":
27
+ return FileResponse("frontend/out/index.html")
28
+
29
+ file_path = Path("frontend/out") / path_name
30
 
 
 
 
31
  if file_path.is_file():
32
+ return file_path
33
+
34
+ html_file_path = file_path.with_suffix(".html")
35
+ if html_file_path.is_file():
36
+ return FileResponse(html_file_path)
37
+
38
+ raise HTTPException(status_code=404, detail="Item not found")
39
 
40
  # Run the application using Uvicorn
41
  if __name__ == "__main__":