@mondaydotcomorg/z2h-cli 0.12.1 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
// /src/page.html (and copies it to /assets/ at build time). Same-origin
|
|
4
|
-
// (the URL lives under whatever host is rendering the app), so the page's
|
|
5
|
-
// fetch() calls carry bigbrain.me auth cookies normally.
|
|
6
|
-
//
|
|
7
|
-
// The iframe gives the page its own document — scripts execute natively,
|
|
8
|
-
// CSS/JS is fully isolated from the host React app, no script reinjection
|
|
9
|
-
// logic needed.
|
|
10
|
-
import React from 'react';
|
|
1
|
+
import React, { useRef, useEffect } from 'react';
|
|
2
|
+
import { getBigBrainAPI } from '@mondaydotcomorg/trident-runtime';
|
|
11
3
|
import pageUrl from './page.html?url';
|
|
12
4
|
|
|
5
|
+
const BACKEND_SUBDOMAIN = 'bigbrain-zth';
|
|
6
|
+
|
|
7
|
+
function getBackendBaseUrl(): string | null {
|
|
8
|
+
const base = getBigBrainAPI()?.contextService?.bigbrainBaseUrl;
|
|
9
|
+
return base ? base.replace('//', `//${BACKEND_SUBDOMAIN}.`) : null;
|
|
10
|
+
}
|
|
11
|
+
|
|
13
12
|
export default function __APP_COMPONENT__() {
|
|
13
|
+
const iframeRef = useRef<HTMLIFrameElement>(null);
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
const handleMessage = (event: MessageEvent) => {
|
|
16
|
+
if (!iframeRef.current || event.source !== iframeRef.current.contentWindow) return;
|
|
17
|
+
if (event.data?.type !== 'z2h:getConfig') return;
|
|
18
|
+
const baseUrl = getBackendBaseUrl();
|
|
19
|
+
if (!baseUrl) return;
|
|
20
|
+
(event.source as Window).postMessage({ type: 'z2h:config', baseUrl }, event.origin);
|
|
21
|
+
};
|
|
22
|
+
window.addEventListener('message', handleMessage);
|
|
23
|
+
return () => window.removeEventListener('message', handleMessage);
|
|
24
|
+
}, []);
|
|
14
25
|
return (
|
|
15
26
|
<iframe
|
|
27
|
+
ref={iframeRef}
|
|
16
28
|
src={pageUrl}
|
|
17
29
|
title="App"
|
|
18
30
|
style={{ width: '100vw', height: '100vh', border: 'none', display: 'block' }}
|