From 81a3b69f6dc36dfc195726755a3b6f9425481365 Mon Sep 17 00:00:00 2001 From: Junwei Zhao Date: Tue, 24 Feb 2026 11:05:07 +1100 Subject: [PATCH] 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> --- backend/app/main.py | 7 +++++++ frontend/vite.config.ts | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/backend/app/main.py b/backend/app/main.py index 50d37a3..6bb15e5 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -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(): diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index ab5758e..d2060be 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -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() },