30 lines
952 B
Python
30 lines
952 B
Python
from fastapi import FastAPI, Request
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from fastapi.responses import JSONResponse
|
|
import httpx
|
|
|
|
SEARCHCRAFT_URL = "http://0.0.0.0:8000"
|
|
|
|
app = FastAPI()
|
|
|
|
# Allow frontend to talk to this proxy (can restrict origins if needed)
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"], # Change to your domain in production
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
|
|
@app.post("/index/{index}/search")
|
|
async def proxy_search(index: str, request: Request):
|
|
"""Proxy search request to Searchcraft backend"""
|
|
body = await request.body()
|
|
async with httpx.AsyncClient() as client:
|
|
response = await client.post(
|
|
f"{SEARCHCRAFT_URL}/index/{index}/search",
|
|
content=body,
|
|
headers={"Content-Type": "application/json"},
|
|
)
|
|
return JSONResponse(content=response.json(), status_code=response.status_code)
|