mirror of
https://github.com/wahyd4/hey-search.git
synced 2026-08-09 05:06:23 +10:00
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:
@@ -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():
|
||||
|
||||
@@ -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() },
|
||||
|
||||
Reference in New Issue
Block a user