MCPcopy Create free account
hub / github.com/RioArisk/claudecode_api_RemoteControl / parseServerAddress

Function parseServerAddress

app/src/modules/utils.js:18–50  ·  view source on GitHub ↗
(input)

Source from the content-addressed store, hash-verified

16}
17
18export function parseServerAddress(input) {
19 const raw = input.trim();
20 if (!raw) return { ok: false, error: 'Please enter a server address' };
21
22 const hasScheme = /^[a-z][a-z0-9+.-]*:\/\//i.test(raw);
23 let url;
24 try {
25 url = new URL(hasScheme ? raw : `ws://${raw}`);
26 } catch {
27 return { ok: false, error: 'Invalid address' };
28 }
29
30 const protocol = url.protocol.toLowerCase();
31 let wsProtocol;
32 if (protocol === 'ws:') wsProtocol = 'ws:';
33 else if (protocol === 'wss:') wsProtocol = 'wss:';
34 else if (protocol === 'http:') wsProtocol = 'ws:';
35 else if (protocol === 'https:') wsProtocol = 'wss:';
36 else return { ok: false, error: 'Use ws://, wss://, http://, https://, or host:port' };
37
38 if (!url.hostname) return { ok: false, error: 'Invalid address' };
39 if (!hasScheme && !url.port) url.port = '3100';
40
41 const wsUrl = new URL(url.toString());
42 wsUrl.protocol = wsProtocol;
43
44 return {
45 ok: true,
46 displayAddr: formatUrlForDisplay(url, hasScheme),
47 wsUrl: wsUrl.toString(),
48 cacheAddr: wsUrl.toString(),
49 };
50}
51
52export function shortenPath(p) {
53 if (!p) return '';

Callers 5

normalizeServerEntryFunction · 0.90
getServerDedupKeyFunction · 0.90
addServerFunction · 0.90
connectToServerFunction · 0.90
saveServerDialogFunction · 0.90

Calls 1

formatUrlForDisplayFunction · 0.70

Tested by

no test coverage detected