|
@@ -4,6 +4,7 @@ from fastapi import APIRouter, Request, HTTPException, Response
|
|
|
import requests
|
|
|
import asyncio
|
|
|
import json
|
|
|
+import traceback
|
|
|
from extensions import logger
|
|
|
|
|
|
TARGET_BASE_URL = "http://172.26.1.85:8530/api"
|
|
@@ -26,6 +27,8 @@ def sync_fetch(method, url, params=None, headers=None, data=None):
|
|
|
headers=dict(response.headers)
|
|
|
)
|
|
|
except Exception as e:
|
|
|
+
|
|
|
+ traceback.print_exc()
|
|
|
raise Exception(f"Requests error: {str(e)}")
|
|
|
|
|
|
@router.api_route("/skwhp/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "PATCH"])
|
|
@@ -41,6 +44,7 @@ async def proxy(request: Request, path: str):
|
|
|
try:
|
|
|
body = await request.body()
|
|
|
except:
|
|
|
+ traceback.print_exc()
|
|
|
body = None
|
|
|
|
|
|
try:
|
|
@@ -51,6 +55,7 @@ async def proxy(request: Request, path: str):
|
|
|
data = json.loads(data)
|
|
|
logger.info(data)
|
|
|
except:
|
|
|
+ traceback.print_exc()
|
|
|
pass
|
|
|
|
|
|
# 使用 asyncio.to_thread 在后台线程中运行同步的 requests 调用
|
|
@@ -65,4 +70,5 @@ async def proxy(request: Request, path: str):
|
|
|
)
|
|
|
return response
|
|
|
except Exception as e:
|
|
|
+ traceback.print_exc()
|
|
|
raise HTTPException(status_code=500, detail=f"代理请求失败: {str(e)}")
|