maia-utsw / main.py
kenton-li's picture
Update main.py
bac61af
raw
history blame contribute delete
966 Bytes
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")