from fastapi import FastAPI, Request import httpx import uvicorn app = FastAPI() BASE_URL = "https://bg5-mianban.hf.space/" @app.api_route("/{full_path:path}", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"]) async def proxy(full_path: str, request: Request): # 解析出目标 URL if full_path.startswith("https/"): target_url = f"https://{full_path[6:]}" # 去掉 "https/" else: return {"error": "Invalid URL format. Please use 'https/' prefix."} # 使用 httpx 转发请求 async with httpx.AsyncClient() as client: response = await client.request( request.method, target_url, headers=request.headers.raw, data=await request.body(), cookies=request.cookies, allow_redirects=False ) # 返回响应 return response.content, response.status_code, response.headers.items() if __name__ == "__main__": uvicorn.run(app, host="0.0.0.0", port=7860)