fix(integrations): 回调地址漏了 /api/v1,生产上打过去是 405
CI / backend (push) Canceled after 0s

生产把应用挂在域名根、路由带 /api/v1 前缀,request.base_url 里没有前缀,
拼出来的地址少了这一段;本地被 Vite 的代理掩盖了。改成从 base_url 截站点根、
前缀一律取 settings.api_prefix,并补一条断言把这个差异钉住。
This commit is contained in:
Steven
2026-11-05 22:06:37 +08:00
parent 90b99f8253
commit c194609193
3 changed files with 17 additions and 2 deletions
+9 -2
View File
@@ -45,6 +45,7 @@ from fastapi.responses import PlainTextResponse
from sqlalchemy import select
from sqlalchemy.exc import IntegrityError
from ..config import get_settings
from ..db import bind_tenant
from ..deps import AdminDep, SessionDep
from ..errors import AppError, ErrorCode
@@ -417,8 +418,14 @@ def _channel_out(channel: BotChannel) -> dict[str, Any]:
def _webhook_url(request: Request, token: str) -> str:
base = str(request.base_url).rstrip("/")
return f"{base}/integrations/clawbot/{token}"
"""拼出机器人要打的那个地址。
不能直接用 `request.base_url`:生产上应用挂在域名根、路由带 `/api/v1` 前缀,
base_url 里没有前缀,拼出来的地址会 405(本地被 Vite 代理掩盖过这个差异)。
所以站点根从 base_url 里截,前缀一律取 `settings.api_prefix`。
"""
base = str(request.base_url).split("/api/")[0].rstrip("/")
return f"{base}{get_settings().api_prefix}/integrations/clawbot/{token}"
@admin_router.get("/{ws_id}/integrations")