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
+18
-9
@@ -55,6 +55,23 @@ function postThemeToFrame(frame: HTMLIFrameElement | null) {
|
||||
frame.contentWindow.postMessage(collectThemePayload(), targetOrigin);
|
||||
}
|
||||
|
||||
const WEKNORA_BACKEND_PREFIX = "/deerflow";
|
||||
|
||||
function buildFrameUrl(framePath: string) {
|
||||
const backendBase = getBackendBaseURL().replace(/\/+$/, "");
|
||||
const backendOrigin = backendBase
|
||||
? new URL(backendBase, window.location.origin).origin
|
||||
: window.location.origin;
|
||||
if (/^https?:\/\//i.test(framePath)) return new URL(framePath);
|
||||
if (framePath.startsWith("/")) {
|
||||
const path = !framePath.startsWith(`${WEKNORA_BACKEND_PREFIX}/`)
|
||||
? `${WEKNORA_BACKEND_PREFIX}${framePath}`
|
||||
: framePath;
|
||||
return new URL(path, backendOrigin);
|
||||
}
|
||||
return new URL(`${backendBase || backendOrigin}/${framePath.replace(/^\/+/, "")}`);
|
||||
}
|
||||
|
||||
export function WeKnoraKnowledgeDetailPage() {
|
||||
const {
|
||||
knowledge_base_id: strategyKnowledgeBaseId,
|
||||
@@ -88,15 +105,7 @@ export function WeKnoraKnowledgeDetailPage() {
|
||||
.then((session) => {
|
||||
if (cancelled) return;
|
||||
const framePath = session.frame_path || "";
|
||||
const backendBase = getBackendBaseURL().replace(/\/+$/, "");
|
||||
const backendOrigin = backendBase
|
||||
? new URL(backendBase, window.location.origin).origin
|
||||
: window.location.origin;
|
||||
const nextUrl = /^https?:\/\//i.test(framePath)
|
||||
? new URL(framePath)
|
||||
: framePath.startsWith("/")
|
||||
? new URL(framePath, backendOrigin)
|
||||
: new URL(`${backendBase || backendOrigin}/${framePath.replace(/^\/+/, "")}`);
|
||||
const nextUrl = buildFrameUrl(framePath);
|
||||
nextUrl.searchParams.set("theme", collectThemePayload().theme);
|
||||
setFrameSrc(nextUrl.toString());
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user