Patch up frontend traversability (moot in the face of bot logic, but nice to have)

This commit is contained in:
Jack Kingsman
2026-02-09 19:33:23 -08:00
parent 333d885bdb
commit 6cacd741b7
+8 -3
View File
@@ -2,7 +2,7 @@ import logging
from contextlib import asynccontextmanager from contextlib import asynccontextmanager
from pathlib import Path from pathlib import Path
from fastapi import FastAPI from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse from fastapi.responses import FileResponse
from fastapi.staticfiles import StaticFiles from fastapi.staticfiles import StaticFiles
@@ -97,11 +97,16 @@ if FRONTEND_DIR.exists():
@app.get("/{path:path}") @app.get("/{path:path}")
async def serve_frontend(path: str): async def serve_frontend(path: str):
"""Serve frontend files, falling back to index.html for SPA routing.""" """Serve frontend files, falling back to index.html for SPA routing."""
file_path = FRONTEND_DIR / path base_dir = FRONTEND_DIR.resolve()
file_path = (FRONTEND_DIR / path).resolve()
try:
file_path.relative_to(base_dir)
except ValueError:
raise HTTPException(status_code=404, detail="Not found") from None
if file_path.exists() and file_path.is_file(): if file_path.exists() and file_path.is_file():
return FileResponse(file_path) return FileResponse(file_path)
# Fall back to index.html for SPA routing # Fall back to index.html for SPA routing
return FileResponse(FRONTEND_DIR / "index.html") return FileResponse(base_dir / "index.html")
@app.get("/") @app.get("/")
async def serve_index(): async def serve_index():