@@ -25,7 +25,7 @@ import { IProductService } from 'vs/platform/product/common/productService';
25
25
// eslint-disable-next-line code-import-patterns
26
26
import type { IWorkbenchConstructionOptions } from 'vs/workbench/workbench.web.api' ;
27
27
import { editorBackground , editorForeground } from 'vs/platform/theme/common/colorRegistry' ;
28
- import { ClientTheme , getPathPrefix , HTTPNotFoundError , WebManifest } from 'vs/server/common/net' ;
28
+ import { ClientTheme , getOriginalUrl , HTTPNotFoundError , relativePath , relativeRoot , WebManifest } from 'vs/server/common/net' ;
29
29
import { IServerThemeService } from 'vs/server/serverThemeService' ;
30
30
import { isFalsyOrWhitespace } from 'vs/base/common/strings' ;
31
31
@@ -193,17 +193,13 @@ export class WebClientServer {
193
193
* PWA manifest file. This informs the browser that the app may be installed.
194
194
*/
195
195
private async _handleManifest ( req : http . IncomingMessage , res : http . ServerResponse , parsedUrl : url . UrlWithParsedQuery ) : Promise < void > {
196
- const pathPrefix = getPathPrefix ( parsedUrl . pathname ! ) ;
196
+ // The manifest URL is used as the base when resolving URLs so we can just
197
+ // use . without having to check the depth since we serve it at the root.
197
198
const clientTheme = await this . fetchClientTheme ( ) ;
198
- const startUrl = pathPrefix . substring (
199
- 0 ,
200
- pathPrefix . lastIndexOf ( '/' ) + 1
201
- ) ;
202
-
203
199
const webManifest : WebManifest = {
204
200
name : this . _productService . nameLong ,
205
201
short_name : this . _productService . nameShort ,
206
- start_url : normalize ( startUrl ) ,
202
+ start_url : '.' ,
207
203
display : 'fullscreen' ,
208
204
'background-color' : clientTheme . backgroundColor ,
209
205
description : 'Run editors on a remote server.' ,
@@ -319,6 +315,8 @@ export class WebClientServer {
319
315
scopes : [ [ 'user:email' ] , [ 'repo' ] ]
320
316
} : undefined ;
321
317
318
+ const base = relativeRoot ( getOriginalUrl ( req ) )
319
+ const vscodeBase = relativePath ( getOriginalUrl ( req ) )
322
320
const data = ( await util . promisify ( fs . readFile ) ( filePath ) ) . toString ( )
323
321
. replace ( '{{WORKBENCH_WEB_CONFIGURATION}}' , escapeAttribute ( JSON . stringify ( < IWorkbenchConstructionOptions > {
324
322
productConfiguration : {
@@ -329,17 +327,18 @@ export class WebClientServer {
329
327
330
328
// Service Worker
331
329
serviceWorker : {
332
- scope : '. /',
333
- url : `./ ${ this . _environmentService . serviceWorkerFileName } `
330
+ scope : vscodeBase + ' /',
331
+ url : vscodeBase + '/' + this . _environmentService . serviceWorkerFileName ,
334
332
} ,
335
333
336
334
// Endpoints
337
- logoutEndpointUrl : './logout' ,
338
- webEndpointUrl : './static' ,
339
- webEndpointUrlTemplate : './static' ,
340
- webviewContentExternalBaseUrlTemplate : './webview/{{uuid}}/' ,
335
+ base,
336
+ logoutEndpointUrl : base + '/logout' ,
337
+ webEndpointUrl : vscodeBase + '/static' ,
338
+ webEndpointUrlTemplate : vscodeBase + '/static' ,
339
+ webviewContentExternalBaseUrlTemplate : vscodeBase + '/webview/{{uuid}}/' ,
341
340
342
- updateUrl : '. /update/check'
341
+ updateUrl : base + ' /update/check'
343
342
} ,
344
343
folderUri : ( workspacePath && isFolder ) ? transformer . transformOutgoing ( URI . file ( workspacePath ) ) : undefined ,
345
344
workspaceUri : ( workspacePath && ! isFolder ) ? transformer . transformOutgoing ( URI . file ( workspacePath ) ) : undefined ,
@@ -355,7 +354,8 @@ export class WebClientServer {
355
354
} ) ) )
356
355
. replace ( / { { CLIENT_ B A C K G R O U N D _ C O L O R } } / g, ( ) => backgroundColor )
357
356
. replace ( / { { CLIENT_ F O R E G R O U N D _ C O L O R } } / g, ( ) => foregroundColor )
358
- . replace ( '{{WORKBENCH_AUTH_SESSION}}' , ( ) => authSessionInfo ? escapeAttribute ( JSON . stringify ( authSessionInfo ) ) : '' ) ;
357
+ . replace ( '{{WORKBENCH_AUTH_SESSION}}' , ( ) => authSessionInfo ? escapeAttribute ( JSON . stringify ( authSessionInfo ) ) : '' )
358
+ . replace ( / { { BASE} } / g, ( ) => vscodeBase ) ;
359
359
360
360
const cspDirectives = [
361
361
'default-src \'self\';' ,
@@ -504,7 +504,7 @@ export class WebClientServer {
504
504
return res . end ( JSON . stringify ( knownCallbackUri ) ) ;
505
505
}
506
506
507
- serveError = async ( _req : http . IncomingMessage , res : http . ServerResponse , code : number , message : string , parsedUrl ?: url . UrlWithParsedQuery ) : Promise < void > => {
507
+ serveError = async ( req : http . IncomingMessage , res : http . ServerResponse , code : number , message : string , parsedUrl ?: url . UrlWithParsedQuery ) : Promise < void > => {
508
508
const { applicationName, commit = 'development' , version } = this . _productService ;
509
509
510
510
res . statusCode = code ;
@@ -532,7 +532,8 @@ export class WebClientServer {
532
532
. replace ( / { { ERROR_ M E S S A G E } } / g, ( ) => message )
533
533
. replace ( / { { ERROR_ F O O T E R } } / g, ( ) => `${ version } - ${ commit } ` )
534
534
. replace ( / { { CLIENT_ B A C K G R O U N D _ C O L O R } } / g, ( ) => clientTheme . backgroundColor )
535
- . replace ( / { { CLIENT_ F O R E G R O U N D _ C O L O R } } / g, ( ) => clientTheme . foregroundColor ) ;
535
+ . replace ( / { { CLIENT_ F O R E G R O U N D _ C O L O R } } / g, ( ) => clientTheme . foregroundColor )
536
+ . replace ( / { { BASE} } / g, ( ) => relativePath ( getOriginalUrl ( req ) ) ) ;
536
537
537
538
res . end ( data ) ;
538
539
} ;
0 commit comments