maia-utsw / main.py
kenton-li's picture
Update main.py
d40e671
raw
history blame
928 Bytes
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
app = FastAPI()
@app.all("/{path:path}")
async def proxy(request: Request, path: str):
async with httpx.AsyncClient() as client:
# 使用相同的方法和路径参数发出请求
method = request.method
url = f"http://52.91.103.39:1234/{path}"
# 转发请求头(可选)
headers = dict(request.headers)
# 转发请求体(如果有的话)
content = await request.body()
# 执行代理请求
response = await client.request(
method=method,
url=url,
headers=headers,
content=content
)
# 返回相同的响应内容和状态码
return JSONResponse(content=response.json(), status_code=response.status_code)
# 启动FastAPI应用
# uvicorn main:app --reload