dengdeyan commited on
Commit
0f428fb
·
1 Parent(s): ff63e03
Files changed (1) hide show
  1. server/main.py +9 -5
server/main.py CHANGED
@@ -78,8 +78,12 @@ app.add_middleware(
78
  # --- Static File Serving for Production ---
79
  # This must come *after* the API routes to avoid conflicts.
80
 
81
- # This mounts the 'static' directory (containing the built React app) at the root.
82
- # The `html=True` argument enables SPA mode, serving `index.html` for any path
83
- # that doesn't match a file. This is the recommended and most robust way to
84
- # serve a Single-Page Application with client-side routing.
85
- app.mount("/", StaticFiles(directory="static", html=True), name="static_root")
 
 
 
 
 
78
  # --- Static File Serving for Production ---
79
  # This must come *after* the API routes to avoid conflicts.
80
 
81
+ # 1. Mount the '/assets' directory for Vite's bundled JS and CSS.
82
+ app.mount("/assets", StaticFiles(directory="static/assets"), name="assets")
83
+
84
+ # 2. A final catch-all route for SPA routing.
85
+ # This is only triggered if a file is not found in the mounted directories above.
86
+ # It serves the main HTML file, allowing React Router to handle the path.
87
+ @app.get("/{full_path:path}")
88
+ async def serve_react_app(full_path: str):
89
+ return FileResponse("static/index.html")