File size: 868 Bytes
ec1323a 50cf058 ec1323a 50cf058 ec1323a 50cf058 ec1323a 50cf058 ec1323a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
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)}")
|