kenton-li commited on
Commit
d1ce9aa
·
1 Parent(s): dfdcbf5

Create main.py

Browse files
Files changed (1) hide show
  1. main.py +33 -0
main.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, Request
2
+ from fastapi.responses import Response
3
+ import httpx
4
+
5
+ app = FastAPI()
6
+
7
+ @app.api_route("/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "HEAD"])
8
+ async def proxy(request: Request, path: str):
9
+ target_url = f"http://www.medicalgpt.club/{path}"
10
+
11
+ async with httpx.AsyncClient() as client:
12
+ method = request.method
13
+ headers = dict(request.headers)
14
+ params = request.query_params
15
+ content = await request.body()
16
+
17
+ response = await client.request(
18
+ method=method,
19
+ url=target_url,
20
+ headers=headers,
21
+ params=params,
22
+ content=content
23
+ )
24
+
25
+ return Response(
26
+ content=response.content,
27
+ status_code=response.status_code,
28
+ headers=dict(response.headers)
29
+ )
30
+
31
+ if __name__ == "__main__":
32
+ import os
33
+ os.system("uvicorn main:app --host 0.0.0.0 --port 7860")