21 lines
1.0 KiB
TypeScript
21 lines
1.0 KiB
TypeScript
// Default master URL offered in the agent install command.
|
|
//
|
|
// The agent registers against {master_url}/panel/api/agent/register, and
|
|
// the panel itself is usually served under a base path (webBasePath, e.g.
|
|
// "/rogue"). Prefilling the bare origin — as the form used to — produced
|
|
// an install command whose registration 404'd, leaving the node stuck at
|
|
// "unknown" on the panel. The address the operator is viewing the panel
|
|
// through already contains the base path, so derive the default from it:
|
|
// origin + window.X_UI_BASE_PATH (injected by the panel server). The
|
|
// operator can still override it (e.g. a public address instead of a LAN
|
|
// or tunnel one).
|
|
export function computeDefaultMasterUrl(origin: string, basePath: string | undefined): string {
|
|
const trimmed = (basePath || '/').replace(/\/+$/, '');
|
|
return origin + trimmed;
|
|
}
|
|
|
|
export function currentPanelMasterUrl(): string {
|
|
if (typeof window === 'undefined') return '';
|
|
return computeDefaultMasterUrl(window.location.origin, window.X_UI_BASE_PATH);
|
|
}
|