@@ -106,7 +106,7 @@ Index: code-server/lib/vscode/src/vs/code/browser/workbench/workbench.ts
106
106
import { create, ICredentialsProvider, IURLCallbackProvider, IWorkbenchConstructionOptions, IWorkspace, IWorkspaceProvider } from 'vs/workbench/workbench.web.main';
107
107
import { posix } from 'vs/base/common/path';
108
108
import { ltrim } from 'vs/base/common/strings';
109
- + import { relativeRoot } from 'vs/server/node/webClientServer ';
109
+ + import { extractLocalHostUriMetaDataForPortMapping } from 'vs/platform/tunnel/common/tunnel ';
110
110
111
111
interface ICredential {
112
112
service: string;
@@ -127,33 +127,23 @@ Index: code-server/lib/vscode/src/vs/code/browser/workbench/workbench.ts
127
127
128
128
// Create workbench
129
129
create(document.body, {
130
- @@ -506,6 +508,32 @@ function doCreateUri(path: string, query
130
+ @@ -506,6 +508,22 @@ function doCreateUri(path: string, query
131
131
} : undefined,
132
132
workspaceProvider: WorkspaceProvider.create(config),
133
133
urlCallbackProvider: new LocalStorageURLCallbackProvider(config.callbackRoute),
134
134
- credentialsProvider: config.remoteAuthority ? undefined : new LocalStorageCredentialsProvider() // with a remote, we don't use a local credentials provider
135
135
+ credentialsProvider: config.remoteAuthority ? undefined : new LocalStorageCredentialsProvider(), // with a remote, we don't use a local credentials provider
136
136
+ resolveExternalUri: (uri: URI): Promise<URI> => {
137
- + // TODO@jsjoeio - how do we make it relative to work when hosted on subpath?
138
- + const baseUrl = `${window.location.protocol}//${window.location.host}`
139
137
+ let resolvedUri = uri
138
+ + const localhostMatch = extractLocalHostUriMetaDataForPortMapping(uri)
140
139
+
141
- + // NOTE@jsjoeio - this isn't exhaustive
142
- + // also doesn't handle if not http or https i.e. ws
143
- + const localhostMatch = uri.toString().includes("localhost")
144
140
+ if (localhostMatch) {
145
- + // Source: extractLocalHostUriMetaDataForPortMapping
146
- + const matches = /^(localhost|127\.0\.0\.1|0\.0\.0\.0):(\d+)$/.exec(uri.authority)
147
- + const port = matches && +matches[2]
148
- + if (port) {
149
- + // Use code-server's built in /proxy/<port>
150
- + resolvedUri = URI.parse(`${baseUrl}/proxy/${port}`)
151
- + } else {
152
- + // If here probably means no port found
153
- + // Assume 80 for HTTP and 443 for HTTPS
154
- + const isHttps = uri.scheme === "https"
155
- + resolvedUri = URI.parse(`${baseUrl}/proxy/${isHttps ? "443" : "80"}`)
141
+ + let baseUrl = `${window.location.protocol}//${window.location.host}`
142
+ + if (config.productConfiguration && config.productConfiguration.proxyEndpointTemplate) {
143
+ + baseUrl = new URL(config.productConfiguration.proxyEndpointTemplate.replace('{{port}}', localhostMatch.port.toString()), window.location.href).toString()
156
144
+ }
145
+ + // Use code-server's built in /proxy/<port>
146
+ + resolvedUri = URI.parse(`${baseUrl}/proxy/${localhostMatch.port}`)
157
147
+ }
158
148
+
159
149
+ // If not localhost, return unmodified
0 commit comments