kenken999's picture
update
ec1323a
raw
history blame
868 Bytes
from fastapi import APIRouter, Request, HTTPException
import httpx
LARAVEL_URL = "http://localhost:8000"
router = APIRouter(prefix="/gradios", tags=["gradios"])
@router.api_route("/route/{path:path}", methods=["GET", "POST", "PUT", "DELETE"])
async def proxy(request: Request, path: str):
async with httpx.AsyncClient() as client:
req_data = await request.body()
try:
proxied = await client.request(
request.method,
f"{LARAVEL_URL}/{path}",
headers=request.headers.raw,
content=req_data
)
# γ‚Ήγƒ†γƒΌγ‚Ώγ‚Ήγ‚³γƒΌγƒ‰γ‚„γƒ˜γƒƒγƒ€γ‚‚εΌ•γηΆ™γŽγŸγ„ε ΄εˆγ―θͺΏζ•΄γ—てください
return proxied.text
except httpx.RequestError as e:
raise HTTPException(status_code=500, detail=f"Request proxy failed: {str(e)}")