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://www.medicalgpt.club/{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 ) # Process the Location header if present in the response response_headers = dict(response.headers) if "Location" in response_headers: # Replace the target URL with the proxy URL response_headers["Location"] = response_headers["Location"].replace("http://www.medicalgpt.club", request.base_url) return Response( content=response.content, status_code=response.status_code, headers=response_headers ) if __name__ == "__main__": import os os.system("uvicorn main:app --host 0.0.0.0 --port 7860")