4
4
* Copyright (c) Microsoft Corporation. All rights reserved.
5
5
* Licensed under the MIT License. See License.txt in the project root for license information.
6
6
*--------------------------------------------------------------------------------------------*/
7
- Object . defineProperty ( exports , '__esModule' , { value : true } ) ;
8
7
9
8
// @ts -check
10
9
@@ -42,17 +41,15 @@ const WEB_PLAYGROUND_VERSION = '0.0.10';
42
41
43
42
const args = minimist ( process . argv , {
44
43
boolean : [
45
- 'launch' ,
44
+ 'no- launch' ,
46
45
'help' ,
47
46
'verbose' ,
48
47
'wrap-iframe' ,
49
48
'enable-sync' ,
50
49
] ,
51
50
string : [
52
- 'server' ,
53
51
'scheme' ,
54
52
'host' ,
55
- 'remote-authority' ,
56
53
'port' ,
57
54
'local_port' ,
58
55
'extension' ,
@@ -63,13 +60,12 @@ const args = minimist(process.argv, {
63
60
if ( args . help ) {
64
61
console . log (
65
62
'yarn web [options]\n' +
66
- ' --launch Open VSCode web in the browser\n' +
63
+ ' --no- launch Do not open VSCode web in the browser\n' +
67
64
' --wrap-iframe Wrap the Web Worker Extension Host in an iframe\n' +
68
65
' --enable-sync Enable sync by default\n' +
69
66
' --scheme Protocol (https or http)\n' +
70
67
' --host Remote host\n' +
71
68
' --port Remote/Local port\n' +
72
- ' --remote-authority Remote auth\n' +
73
69
' --local_port Local port override\n' +
74
70
' --secondary-port Secondary port\n' +
75
71
' --extension Path of an extension to include\n' +
@@ -225,10 +221,8 @@ const mapCallbackUriToRequestId = new Map();
225
221
/**
226
222
* @param req {http.IncomingMessage}
227
223
* @param res {http.ServerResponse}
228
- * @param webConfigJSON {import('../../src/vs/workbench/workbench.web.api').IServerWorkbenchConstructionOptions}
229
- * @param webConfigJSON undefined
230
224
*/
231
- const requestHandler = ( req , res , webConfigJSON ) => {
225
+ const requestHandler = ( req , res ) => {
232
226
const parsedUrl = url . parse ( req . url , true ) ;
233
227
const pathname = parsedUrl . pathname ;
234
228
@@ -259,9 +253,6 @@ const requestHandler = (req, res, webConfigJSON) => {
259
253
return handleExtension ( req , res , parsedUrl ) ;
260
254
}
261
255
if ( pathname === '/' ) {
262
- if ( args . server ) {
263
- return handleRootFromServer ( req , res , webConfigJSON ) ;
264
- }
265
256
// main web
266
257
return handleRoot ( req , res ) ;
267
258
} else if ( pathname === '/callback' ) {
@@ -270,11 +261,8 @@ const requestHandler = (req, res, webConfigJSON) => {
270
261
} else if ( pathname === '/fetch-callback' ) {
271
262
// callback fetch support
272
263
return handleFetchCallback ( req , res , parsedUrl ) ;
273
- } else if ( pathname === '/vscode-remote-resource' ) {
274
- // callback fetch support
275
- return handleRemoteResource ( req , res , parsedUrl ) ;
276
264
} else if ( pathname === '/builtin' ) {
277
- // builtin extensions JSON
265
+ // builtin extnesions JSON
278
266
return handleBuiltInExtensions ( req , res , parsedUrl ) ;
279
267
}
280
268
@@ -286,28 +274,26 @@ const requestHandler = (req, res, webConfigJSON) => {
286
274
}
287
275
} ;
288
276
289
- if ( ! args . server ) {
290
- const server = http . createServer ( requestHandler ) ;
291
- server . listen ( LOCAL_PORT , ( ) => {
292
- if ( LOCAL_PORT !== PORT ) {
293
- console . log ( `Operating location at http://0.0.0.0:${ LOCAL_PORT } ` ) ;
294
- }
295
- console . log ( `Web UI available at ${ SCHEME } ://${ AUTHORITY } ` ) ;
296
- } ) ;
297
- server . on ( 'error' , err => {
298
- console . error ( `Error occurred in server:` ) ;
299
- console . error ( err ) ;
300
- } ) ;
277
+ const server = http . createServer ( requestHandler ) ;
278
+ server . listen ( LOCAL_PORT , ( ) => {
279
+ if ( LOCAL_PORT !== PORT ) {
280
+ console . log ( `Operating location at http://0.0.0.0:${ LOCAL_PORT } ` ) ;
281
+ }
282
+ console . log ( `Web UI available at ${ SCHEME } ://${ AUTHORITY } ` ) ;
283
+ } ) ;
284
+ server . on ( 'error' , err => {
285
+ console . error ( `Error occurred in server:` ) ;
286
+ console . error ( err ) ;
287
+ } ) ;
301
288
302
- const secondaryServer = http . createServer ( requestHandler ) ;
303
- secondaryServer . listen ( SECONDARY_PORT , ( ) => {
304
- console . log ( `Secondary server available at ${ SCHEME } ://${ HOST } :${ SECONDARY_PORT } ` ) ;
305
- } ) ;
306
- secondaryServer . on ( 'error' , err => {
307
- console . error ( `Error occurred in server:` ) ;
308
- console . error ( err ) ;
309
- } ) ;
310
- }
289
+ const secondaryServer = http . createServer ( requestHandler ) ;
290
+ secondaryServer . listen ( SECONDARY_PORT , ( ) => {
291
+ console . log ( `Secondary server available at ${ SCHEME } ://${ HOST } :${ SECONDARY_PORT } ` ) ;
292
+ } ) ;
293
+ secondaryServer . on ( 'error' , err => {
294
+ console . error ( `Error occurred in server:` ) ;
295
+ console . error ( err ) ;
296
+ } ) ;
311
297
312
298
/**
313
299
* @param {import('http').IncomingMessage } req
@@ -331,20 +317,6 @@ async function handleBuiltInExtensions(req, res, parsedUrl) {
331
317
return res . end ( JSON . stringify ( extensions ) ) ;
332
318
}
333
319
334
- /**
335
- * @param {import('http').IncomingMessage } req
336
- * @param {import('http').ServerResponse } res
337
- * @param {import('url').UrlWithParsedQuery } parsedUrl
338
- */
339
- async function handleRemoteResource ( req , res , parsedUrl ) {
340
- const { path } = parsedUrl . query ;
341
-
342
- if ( path ) {
343
- res . setHeader ( 'Content-Type' , getMediaMime ( path ) ) ;
344
- res . end ( await readFile ( path ) ) ;
345
- }
346
- }
347
-
348
320
/**
349
321
* @param {import('http').IncomingMessage } req
350
322
* @param {import('http').ServerResponse } res
@@ -448,7 +420,6 @@ async function handleRoot(req, res) {
448
420
? req . headers [ 'host' ] . replace ( ':' + PORT , ':' + SECONDARY_PORT )
449
421
: `${ HOST } :${ SECONDARY_PORT } `
450
422
) ;
451
-
452
423
const webConfigJSON = {
453
424
folderUri : folderUri ,
454
425
staticExtensions,
@@ -486,37 +457,6 @@ async function handleRoot(req, res) {
486
457
return res . end ( data ) ;
487
458
}
488
459
489
- /**
490
- * @param {import('http').IncomingMessage } req
491
- * @param {import('http').ServerResponse } res
492
- * @param webConfigJSON {import('../../src/vs/workbench/workbench.web.api').IServerWorkbenchConstructionOptions}
493
- */
494
- async function handleRootFromServer ( req , res , webConfigJSON ) {
495
- if ( args . verbose ) {
496
- fancyLog ( `${ ansiColors . magenta ( 'BuiltIn extensions' ) } : ${ dedupedBuiltInExtensions . map ( e => path . basename ( e . extensionPath ) ) . join ( ', ' ) } ` ) ;
497
- fancyLog ( `${ ansiColors . magenta ( 'Additional extensions' ) } : ${ additionalBuiltinExtensions . map ( e => path . basename ( e . extensionLocation . path ) ) . join ( ', ' ) || 'None' } ` ) ;
498
- }
499
-
500
- if ( req . headers [ 'x-forwarded-host' ] ) {
501
- // support for running in codespace => no iframe wrapping
502
- delete webConfigJSON . webWorkerExtensionHostIframeSrc ;
503
- }
504
- const authSessionInfo = undefined ;
505
-
506
- const data = ( await readFile ( WEB_MAIN ) ) . toString ( )
507
- . replace ( '{{WORKBENCH_WEB_CONFIGURATION}}' , ( ) => escapeAttribute ( JSON . stringify ( webConfigJSON ) ) ) // use a replace function to avoid that regexp replace patterns ($&, $0, ...) are applied
508
- . replace ( '{{WORKBENCH_AUTH_SESSION}}' , ( ) => authSessionInfo ? escapeAttribute ( JSON . stringify ( authSessionInfo ) ) : '' )
509
- . replace ( '{{WEBVIEW_ENDPOINT}}' , '' ) ;
510
-
511
- const headers = {
512
- 'Content-Type' : 'text/html' ,
513
- 'Content-Security-Policy' : 'require-trusted-types-for \'script\';'
514
- } ;
515
-
516
- res . writeHead ( 200 , headers ) ;
517
- return res . end ( data ) ;
518
- }
519
-
520
460
/**
521
461
* Handle HTTP requests for /callback
522
462
* @param {import('http').IncomingMessage } req
@@ -676,7 +616,7 @@ const mapExtToMediaMimes = {
676
616
function getMediaMime ( forPath ) {
677
617
const ext = path . extname ( forPath ) ;
678
618
679
- return mapExtToMediaMimes [ ext . toLowerCase ( ) ] || 'text/plain' ;
619
+ return mapExtToMediaMimes [ ext . toLowerCase ( ) ] ;
680
620
}
681
621
682
622
/**
@@ -717,6 +657,4 @@ async function serveFile(req, res, filePath, responseHeaders = Object.create(nul
717
657
718
658
if ( args . launch !== false ) {
719
659
opn ( `${ SCHEME } ://${ HOST } :${ PORT } ` ) ;
720
- }
721
-
722
- exports . requestHandler = requestHandler ;
660
+ }
0 commit comments