File size: 966 Bytes
0bc2ea1 410891c 07afc08 0bc2ea1 07afc08 0bc2ea1 bac61af 410891c 0bc2ea1 410891c 0bc2ea1 410891c 0bc2ea1 410891c 0bc2ea1 410891c 0bc2ea1 410891c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
from fastapi import FastAPI, Request
from fastapi.responses import Response
import httpx
app = FastAPI()
@app.api_route("/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "HEAD"])
async def proxy(request: Request, path: str):
target_url = f"http://216.128.139.239:1234/{path}"
async with httpx.AsyncClient() as client:
method = request.method
headers = dict(request.headers)
params = request.query_params
content = await request.body()
response = await client.request(
method=method,
url=target_url,
headers=headers,
params=params,
content=content
)
return Response(
content=response.content,
status_code=response.status_code,
headers=dict(response.headers)
)
if __name__ == "__main__":
import os
os.system("uvicorn main:app --host 0.0.0.0 --port 7860")
|