@@ -111,65 +111,53 @@ Index: code-server/lib/vscode/src/vs/server/node/webClientServer.ts
111111===================================================================
112112--- code-server.orig/lib/vscode/src/vs/server/node/webClientServer.ts
113113+++ code-server/lib/vscode/src/vs/server/node/webClientServer.ts
114- @@ -271,16 +271,15 @@ export class WebClientServer {
115- return void res.end();
116- }
114+ @@ -246,7 +246,9 @@ export class WebClientServer {
115+ };
116+
117+ // Prefix routes with basePath for clients
118+ - const basePath = getFirstHeader('x-forwarded-prefix') || this._basePath;
119+ + const rootBase = relativeRoot(getOriginalUrl(req))
120+ + const vscodeBase = relativePath(getOriginalUrl(req))
121+ + const basePath = vscodeBase || getFirstHeader('x-forwarded-prefix') || this._basePath;
122+
123+ const queryConnectionToken = parsedUrl.query[connectionTokenQueryName];
124+ if (typeof queryConnectionToken === 'string') {
125+ @@ -285,10 +287,14 @@ export class WebClientServer {
126+ };
117127
118- - const getFirstHeader = (headerName: string) => {
119- - const val = req.headers[headerName];
120- - return Array.isArray(val) ? val[0] : val;
121- - };
122- -
123128 const useTestResolver = (!this._environmentService.isBuilt && this._environmentService.args['use-test-resolver']);
124129+ // For now we are getting the remote authority from the client to avoid
125130+ // needing specific configuration for reverse proxies to work. Set this to
126131+ // something invalid to make sure we catch code that is using this value
127132+ // from the backend when it should not.
128- const remoteAuthority = (
133+ let remoteAuthority = (
129134 useTestResolver
130135 ? 'test+test'
131136- : (getFirstHeader('x-original-host') || getFirstHeader('x-forwarded-host') || req.headers.host)
132137+ : 'remote'
133138 );
134139 if (!remoteAuthority) {
135140 return serveError(req, res, 400, `Bad request.`);
136- @@ -307,8 +306,12 @@ export class WebClientServer {
137- scopes: [['user:email'], ['repo']]
138- } : undefined;
141+ @@ -335,6 +341,7 @@ export class WebClientServer {
139142
140- + const base = relativeRoot(getOriginalUrl(req))
141- + const vscodeBase = relativePath(getOriginalUrl(req))
142- +
143143 const productConfiguration = {
144144 codeServerVersion: this._productService.codeServerVersion,
145- + rootEndpoint: base ,
145+ + rootEndpoint: rootBase ,
146146 embedderIdentifier: 'server-distro',
147147 extensionsGallery: this._webExtensionResourceUrlTemplate && this._productService.extensionsGallery ? {
148148 ...this._productService.extensionsGallery,
149- @@ -337,7 +340,7 @@ export class WebClientServer {
150- folderUri: resolveWorkspaceURI(this._environmentService.args['default-folder']),
151- workspaceUri: resolveWorkspaceURI(this._environmentService.args['default-workspace']),
152- productConfiguration,
153- - callbackRoute: this._callbackRoute
154- + callbackRoute: vscodeBase + this._callbackRoute
155- };
156-
157- const cookies = cookie.parse(req.headers.cookie || '');
158- @@ -354,9 +357,11 @@ export class WebClientServer {
159- const values: { [key: string]: string } = {
160- WORKBENCH_WEB_CONFIGURATION: asJSON(workbenchWebConfiguration),
149+ @@ -382,7 +389,9 @@ export class WebClientServer {
161150 WORKBENCH_AUTH_SESSION: authSessionInfo ? asJSON(authSessionInfo) : '',
162- - WORKBENCH_WEB_BASE_URL: this._staticRoute,
163- + WORKBENCH_WEB_BASE_URL: vscodeBase + this._staticRoute,
151+ WORKBENCH_WEB_BASE_URL: staticRoute,
164152 WORKBENCH_NLS_URL,
165- - WORKBENCH_NLS_FALLBACK_URL: `${this._staticRoute }/out/nls.messages.js`
166- + WORKBENCH_NLS_FALLBACK_URL: `${vscodeBase}${this._staticRoute }/out/nls.messages.js`,
167- + BASE: base ,
168- + VS_BASE: vscodeBase ,
153+ - WORKBENCH_NLS_FALLBACK_URL: `${staticRoute }/out/nls.messages.js`
154+ + WORKBENCH_NLS_FALLBACK_URL: `${staticRoute }/out/nls.messages.js`,
155+ + BASE: rootBase ,
156+ + VS_BASE: basePath ,
169157 };
170158
171159 // DEV ---------------------------------------------------------------------------------------
172- @@ -393 ,7 +398 ,7 @@ export class WebClientServer {
160+ @@ -419 ,7 +428 ,7 @@ export class WebClientServer {
173161 'default-src \'self\';',
174162 'img-src \'self\' https: data: blob:;',
175163 'media-src \'self\';',
@@ -178,7 +166,7 @@ Index: code-server/lib/vscode/src/vs/server/node/webClientServer.ts
178166 'child-src \'self\';',
179167 `frame-src 'self' https://*.vscode-cdn.net data:;`,
180168 'worker-src \'self\' data: blob:;',
181- @@ -466 ,3 +471 ,70 @@ export class WebClientServer {
169+ @@ -492 ,3 +501 ,70 @@ export class WebClientServer {
182170 return void res.end(data);
183171 }
184172 }
0 commit comments