MCPcopy
hub / github.com/MetaCubeX/metacubexd / resolveControlConfig

Function resolveControlConfig

packages/ui/composables/useControlApi.ts:29–50  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

27}
28
29export 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
52function stripTrailingSlash(s: string): string {
53 return s.replace(/\/$/, '')

Callers 2

useControlApiFunction · 0.85

Calls 1

stripTrailingSlashFunction · 0.85

Tested by

no test coverage detected