update
Browse files- routers/proxy.py +17 -28
routers/proxy.py
CHANGED
|
@@ -1,33 +1,22 @@
|
|
|
|
|
| 1 |
import httpx
|
| 2 |
-
#from fastapi import FastAPI, Request
|
| 3 |
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
import json
|
| 7 |
-
import os
|
| 8 |
-
# current_user: User = Depends(get_current_active_user)):
|
| 9 |
-
# oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/token")
|
| 10 |
-
# current_user: User = Depends(get_current_active_user)):
|
| 11 |
-
# oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/token")
|
| 12 |
|
| 13 |
-
|
| 14 |
-
from gradio_client import Client
|
| 15 |
-
|
| 16 |
-
#router = APIRouter()
|
| 17 |
-
router = APIRouter(prefix="/gradio", tags=["gradio"])
|
| 18 |
-
@router.get("/route/proxy")
|
| 19 |
-
|
| 20 |
-
#LARAVEL_URL="http://localhost:8000"
|
| 21 |
-
LARAVEL_URL="http://localhost:8000"
|
| 22 |
-
|
| 23 |
-
@app.api_route("/{path:path}", methods=["GET", "POST", "PUT", "DELETE"])
|
| 24 |
async def proxy(request: Request, path: str):
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import APIRouter, Request, HTTPException
|
| 2 |
import httpx
|
|
|
|
| 3 |
|
| 4 |
+
LARAVEL_URL = "http://localhost:8000"
|
| 5 |
|
| 6 |
+
router = APIRouter(prefix="/gradios", tags=["gradios"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
@router.api_route("/route/{path:path}", methods=["GET", "POST", "PUT", "DELETE"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
async def proxy(request: Request, path: str):
|
| 10 |
+
async with httpx.AsyncClient() as client:
|
| 11 |
+
req_data = await request.body()
|
| 12 |
+
try:
|
| 13 |
+
proxied = await client.request(
|
| 14 |
+
request.method,
|
| 15 |
+
f"{LARAVEL_URL}/{path}",
|
| 16 |
+
headers=request.headers.raw,
|
| 17 |
+
content=req_data
|
| 18 |
+
)
|
| 19 |
+
# 銈广儐銉笺偪銈广偝銉笺儔銈勩儤銉冦儉銈傚紩銇嶇稒銇庛仧銇勫牬鍚堛伅瑾挎暣銇椼仸銇忋仩銇曘亜
|
| 20 |
+
return proxied.text
|
| 21 |
+
except httpx.RequestError as e:
|
| 22 |
+
raise HTTPException(status_code=500, detail=f"Request proxy failed: {str(e)}")
|