Support for SPA Frameworks in StaticFiles? #2908
-
Hi, I work in an industry where I need to serve static files directly through Starlette without using Nginx. As a junior developer, I apologize in advance if my explanation lacks clarity. For example, I serve static files using the following: app.mount("/ui", StaticFiles(directory=str(ui_path), html=True), name="ui") However, when my React-built web page makes a request to /ui/viewer, it results in an HTTPException with a 404 error because viewer is a React routing URI, not an actual static file. My questions: I appreciate your time and look forward to your response. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You need a catch-all route like |
Beta Was this translation helpful? Give feedback.
You need a catch-all route like
Route('/ui/{path:path}')
orMount('/ui', app)
. It will intercept all requests and route them to a endpoint that serves your HTML file.https://www.starlette.io/routing/#path-parameters