Update app.py
Browse files
app.py
CHANGED
|
@@ -26,15 +26,17 @@ async def get_http_client():
|
|
| 26 |
http2=True
|
| 27 |
)
|
| 28 |
|
| 29 |
-
# 处理 /api
|
| 30 |
-
@app.api_route("/api
|
| 31 |
-
async def
|
| 32 |
-
|
| 33 |
-
if rest.startswith('/'):
|
| 34 |
-
rest = rest[1:]
|
| 35 |
-
return await proxy_handler(rest, request)
|
| 36 |
|
| 37 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
@app.api_route("/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD", "PATCH"])
|
| 39 |
async def general_proxy(path: str, request: Request):
|
| 40 |
return await proxy_handler(path, request)
|
|
|
|
| 26 |
http2=True
|
| 27 |
)
|
| 28 |
|
| 29 |
+
# 处理 /api 路径
|
| 30 |
+
@app.api_route("/api", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD", "PATCH"])
|
| 31 |
+
async def api_root(request: Request):
|
| 32 |
+
return await proxy_handler("", request) # 传空字符串,直接访问根路径
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
# 处理 /api/xxx 路径
|
| 35 |
+
@app.api_route("/api/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD", "PATCH"])
|
| 36 |
+
async def api_proxy(path: str, request: Request):
|
| 37 |
+
return await proxy_handler(path, request)
|
| 38 |
+
|
| 39 |
+
# 处理其他所有路径
|
| 40 |
@app.api_route("/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD", "PATCH"])
|
| 41 |
async def general_proxy(path: str, request: Request):
|
| 42 |
return await proxy_handler(path, request)
|