-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathprepareBackend.ts
51 lines (38 loc) · 1.43 KB
/
prepareBackend.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import type {NodeAddress} from '../types/additionalProps';
import {parseBalancer, removeViewerPathname} from './parseBalancer';
const https = 'https://';
export const prepareHost = (host?: string) => {
// add "u-" prefix to cloud din nodes
return host?.startsWith('vm-') ? `u-${host}` : host;
};
export const getBackendFromNodeHost = (nodeHost: string, balancer: string) => {
const preparedHost = prepareHost(nodeHost);
const proxy = parseBalancer(balancer).proxy;
if (proxy) {
return https + proxy + '/' + preparedHost;
}
return https + preparedHost;
};
/** For multi-cluster version */
export const getBackendFromRawNodeData = (
node: NodeAddress,
balancer: string,
useBalancerAsBackend?: boolean,
) => {
const {Host, Endpoints, NodeId} = node;
if (useBalancerAsBackend && NodeId) {
const preparedBalancer = removeViewerPathname(balancer);
return `${preparedBalancer}/node/${NodeId}`;
}
if (Host && Endpoints) {
const nodePort = Endpoints.find((endpoint) => endpoint.Name === 'http-mon')?.Address;
if (!nodePort || !Host) {
return undefined;
}
const hostWithPort = Host + nodePort;
// Currently this func is used to get link to developerUI for specific node
// It's expected with / at the end (code in embedded version)
return getBackendFromNodeHost(hostWithPort, balancer);
}
return undefined;
};