|
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): |
|
|
|
if full_path.startswith("https/"): |
|
target_url = f"https://{full_path[6:]}" |
|
else: |
|
return {"error": "Invalid URL format. Please use 'https/' prefix."} |
|
|
|
|
|
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) |
|
|