Fix SPA routing: fallback to index.html for Vue Router paths
Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 4s
Test / build-check (push) Successful in 3s
PR Preview / test (pull_request) Successful in 4s
PR Preview / deploy-preview (pull_request) Successful in 8s
Test / e2e-test (push) Failing after 23s
Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 4s
Test / build-check (push) Successful in 3s
PR Preview / test (pull_request) Successful in 4s
PR Preview / deploy-preview (pull_request) Successful in 8s
Test / e2e-test (push) Failing after 23s
Direct navigation to /bugs, /oils, /manage etc. returned 404 because FastAPI's StaticFiles only served index.html for /. Now all non-API, non-asset routes return index.html so Vue Router handles client-side routing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1494,4 +1494,18 @@ def startup():
|
||||
seed_defaults(data["oils_meta"], data["recipes"])
|
||||
|
||||
if os.path.isdir(FRONTEND_DIR):
|
||||
app.mount("/", StaticFiles(directory=FRONTEND_DIR, html=True), name="frontend")
|
||||
# Serve static assets (js/css/images) directly
|
||||
app.mount("/assets", StaticFiles(directory=os.path.join(FRONTEND_DIR, "assets")), name="assets")
|
||||
app.mount("/public", StaticFiles(directory=FRONTEND_DIR), name="public")
|
||||
|
||||
# SPA fallback: any non-API, non-asset route returns index.html
|
||||
from fastapi.responses import FileResponse
|
||||
|
||||
@app.get("/{path:path}")
|
||||
async def spa_fallback(path: str):
|
||||
# Serve actual files if they exist (favicon, icons, etc.)
|
||||
file_path = os.path.join(FRONTEND_DIR, path)
|
||||
if os.path.isfile(file_path):
|
||||
return FileResponse(file_path)
|
||||
# Otherwise return index.html for Vue Router
|
||||
return FileResponse(os.path.join(FRONTEND_DIR, "index.html"))
|
||||
|
||||
Reference in New Issue
Block a user