( host: string, port: number, agentName: string, workspaceName: string, username: string, protocol: WorkspaceAgentPortShareProtocol, pathname?: string, search?: string, )
| 23 | }; |
| 24 | |
| 25 | export 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. |
no outgoing calls
no test coverage detected