fix: route WeKnora embed through backend prefix
This commit is contained in:
1 parent
6dbaf40f99
commit
54fd0e7316
5 files changed
+81
-17
No files matched your search
@@ -1647,6 +1647,7 @@ This gateway provides custom endpoints for models, MCP configuration, skills, an
|
||||
# /assets, /locales and /api/v1/*. Register that proxy last so it stays a
|
||||
# true fallback and cannot intercept DeerFlow APIs.
|
||||
app.include_router(llmwiki.proxy_router)
|
||||
app.include_router(llmwiki.proxy_router, prefix="/deerflow")
|
||||
|
||||
return app
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ proxy_router = APIRouter(tags=["llmwiki-proxy"])
|
||||
|
||||
_MAX_UPLOAD_BYTES = 100 * 1024 * 1024
|
||||
_WEKNORA_ADMIN_SESSION_CACHE: dict[str, dict[str, Any]] = {}
|
||||
_WEKNORA_PUBLIC_PREFIX = "/deerflow"
|
||||
_HOP_BY_HOP_RESPONSE_HEADERS = {
|
||||
"connection",
|
||||
"content-encoding",
|
||||
@@ -517,12 +518,7 @@ def _normalize_public_prefix(value: str | None) -> str:
|
||||
|
||||
|
||||
def _request_public_prefix(request: Request) -> str:
|
||||
headers = request.headers
|
||||
for key in ("x-forwarded-prefix", "x-script-name"):
|
||||
prefix = _normalize_public_prefix(headers.get(key))
|
||||
if prefix:
|
||||
return prefix
|
||||
return _normalize_public_prefix(str(request.scope.get("root_path") or ""))
|
||||
return _WEKNORA_PUBLIC_PREFIX
|
||||
|
||||
|
||||
def _with_public_prefix(prefix: str, path: str) -> str:
|
||||
@@ -531,6 +527,14 @@ def _with_public_prefix(prefix: str, path: str) -> str:
|
||||
return f"{prefix}{path}" if prefix else path
|
||||
|
||||
|
||||
def _without_public_prefix(prefix: str, path: str) -> str:
|
||||
if prefix and path.startswith(f"{prefix}/"):
|
||||
return path[len(prefix):]
|
||||
if prefix and path == prefix:
|
||||
return "/"
|
||||
return path
|
||||
|
||||
|
||||
def _rewrite_weknora_html_public_paths(html: str, public_prefix: str) -> str:
|
||||
if not public_prefix:
|
||||
return html
|
||||
@@ -1538,7 +1542,10 @@ async def proxy_weknora_root_asset(request: Request) -> Response:
|
||||
return await _proxy_weknora_request(
|
||||
request,
|
||||
target_base_url=runtime.web_base_url,
|
||||
upstream_path=str(request.scope.get("path") or request.url.path),
|
||||
upstream_path=_without_public_prefix(
|
||||
_request_public_prefix(request),
|
||||
str(request.scope.get("path") or request.url.path),
|
||||
),
|
||||
ctx=ctx,
|
||||
is_api=False,
|
||||
)
|
||||
|
||||
@@ -41,6 +41,7 @@ class WeKnoraEmbedContext:
|
||||
|
||||
|
||||
def is_weknora_embed_proxy_path(path: str) -> bool:
|
||||
path = path.removeprefix("/deerflow")
|
||||
return (
|
||||
path == "/platform"
|
||||
or path.startswith("/platform/")
|
||||
|
||||
Reference in new issue
Block a user