fix: add /search alias so external clients don't get 404

- Vite dev server: proxy /search to backend with path rewrite to /api/search
- FastAPI: add GET+POST /search route that 307-redirects to /api/search
  (307 preserves the original HTTP method, so POST stays POST)
- Fixes 404 for clients calling /search instead of /api/search

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-02-24 11:05:07 +11:00
co-authored by Copilot
parent efc237ae52
commit 81a3b69f6d
2 changed files with 12 additions and 0 deletions
+7
View File
@@ -120,6 +120,13 @@ async def global_exception_handler(request: Request, exc: Exception):
app.include_router(router, prefix="/api")
# Alias /search → /api/search for compatibility with external clients
@app.api_route("/search", methods=["GET", "POST"], include_in_schema=False)
async def search_root_alias(request: Request):
url = request.url.replace(path="/api/search")
from fastapi.responses import RedirectResponse
return RedirectResponse(url=str(url), status_code=307)
# Serve frontend static files if they exist (production / Docker)
static_dir = Path(__file__).resolve().parent.parent / "static"
if static_dir.is_dir():
+5
View File
@@ -28,6 +28,11 @@ export default defineConfig({
server: {
proxy: {
'/api': { target: 'http://localhost:8000', ...forwardHost() },
'/search': {
target: 'http://localhost:8000',
rewrite: (path) => path.replace(/^\/search/, '/api/search'),
...forwardHost(),
},
'/docs': { target: 'http://localhost:8000', ...forwardHost() },
'/redoc': { target: 'http://localhost:8000', ...forwardHost() },
'/openapi.json': { target: 'http://localhost:8000', ...forwardHost() },