MCPcopy Index your code
hub / github.com/coder/coder / portForwardURL

Function portForwardURL

site/src/utils/portForward.ts:25–55  ·  view source on GitHub ↗
(
	host: string,
	port: number,
	agentName: string,
	workspaceName: string,
	username: string,
	protocol: WorkspaceAgentPortShareProtocol,
	pathname?: string,
	search?: string,
)

Source from the content-addressed store, hash-verified

23};
24
25export const portForwardURL = (
26 host: string,
27 port: number,
28 agentName: string,
29 workspaceName: string,
30 username: string,
31 protocol: WorkspaceAgentPortShareProtocol,
32 pathname?: string,
33 search?: string,
34): string => {
35 const { location } = window;
36 const suffix = protocol === "https" ? "s" : "";
37
38 const subdomain = `${port}${suffix}--${agentName}--${workspaceName}--${username}`;
39
40 const baseUrl = `${location.protocol}//${host.replace(/\*/g, subdomain)}`;
41 try {
42 const url = new URL(baseUrl);
43 if (pathname) {
44 url.pathname = pathname;
45 }
46 if (search) {
47 url.search = search;
48 }
49 return url.toString();
50 } catch {
51 // When the proxy host is empty or invalid, return a do-nothing anchor
52 // so the link renders without navigating anywhere.
53 return "#";
54 }
55};
56
57/**
58 * Rewrite a localhost URL to use the workspace port-forward subdomain.

Callers 6

AgentDevcontainerCardFunction · 0.90
PortForwardPopoverViewFunction · 0.90
ListeningPortItemFunction · 0.90
SharedPortItemFunction · 0.90
rewriteLocalhostURLFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected