init
This commit is contained in:
commit
a153bf1bb4
9 changed files with 1808 additions and 0 deletions
30
proxy.py
Normal file
30
proxy.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue