bobocup commited on
Commit
7c2325b
·
verified ·
1 Parent(s): 784f4da

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -26,15 +26,17 @@ async def get_http_client():
26
  http2=True
27
  )
28
 
29
- # 处理 /api 和 /api/v1 的特殊路由
30
- @app.api_route("/api{rest:path}", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD", "PATCH"])
31
- async def api_proxy(rest: str, request: Request):
32
- # 移除开头的斜杠,因为 TARGET_URL 已经包含了斜杠
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)