()
| 27 | } |
| 28 | |
| 29 | export function resolveControlConfig(): ControlConfig { |
| 30 | const w = |
| 31 | typeof window !== 'undefined' |
| 32 | ? (window as unknown as { |
| 33 | metacubexd?: MetacubexdBridge |
| 34 | __METACUBEXD_CONFIG__?: { controlToken?: string } |
| 35 | }) |
| 36 | : undefined |
| 37 | const bridge = w?.metacubexd?.control |
| 38 | if (bridge?.base) { |
| 39 | return { base: stripTrailingSlash(bridge.base), token: bridge.token } |
| 40 | } |
| 41 | const origin = |
| 42 | typeof window !== 'undefined' && window.location?.origin |
| 43 | ? window.location.origin |
| 44 | : '' |
| 45 | // All-in-One server mode: the dashboard is served same-origin with the agent, |
| 46 | // and the server injects CONTROL_TOKEN into config.js so control unlocks |
| 47 | // automatically (#2074). Plain static deploys leave controlToken undefined. |
| 48 | const token = w?.__METACUBEXD_CONFIG__?.controlToken || undefined |
| 49 | return { base: `${stripTrailingSlash(origin)}/api/control`, token } |
| 50 | } |
| 51 | |
| 52 | function stripTrailingSlash(s: string): string { |
| 53 | return s.replace(/\/$/, '') |
no test coverage detected