@@ -169,6 +169,11 @@ function getMediaMime(forPath: string): string | undefined {
169169 return mapExtToMediaMimes . get ( ext . toLowerCase ( ) ) ;
170170}
171171
172+ function serveError ( req : http . IncomingMessage , res : http . ServerResponse , errorCode : number , errorMessage : string ) : void {
173+ res . writeHead ( errorCode , { 'Content-Type' : 'text/plain' } ) ;
174+ res . end ( errorMessage ) ;
175+ }
176+
172177async function serveFile ( logService : ILogService , req : http . IncomingMessage , res : http . ServerResponse , filePath : string , responseHeaders : http . OutgoingHttpHeaders = { } ) {
173178 try {
174179
@@ -199,9 +204,29 @@ async function serveFile(logService: ILogService, req: http.IncomingMessage, res
199204 }
200205}
201206
202- function serveError ( req : http . IncomingMessage , res : http . ServerResponse , errorCode : number , errorMessage : string ) : void {
203- res . writeHead ( errorCode , { 'Content-Type' : 'text/plain' } ) ;
204- res . end ( errorMessage ) ;
207+ async function handleRoot ( req : http . IncomingMessage , resp : http . ServerResponse , entryPointPath : string , environmentService : INativeEnvironmentService ) {
208+ if ( ! req . headers . host ) {
209+ return serveError ( req , resp , 400 , 'Bad request.' ) ;
210+ }
211+
212+ const host = req . headers . host ;
213+
214+ const workbenchConfig = {
215+ remoteAuthority : host ,
216+ developmentOptions : {
217+ enableSmokeTestDriver : environmentService . driverHandle === 'web' ? true : undefined
218+ }
219+ } ;
220+
221+ const escapeQuote = ( str : string ) => str . replace ( / " / g, '"' ) ;
222+ const entryPointContent = ( await fs . promises . readFile ( entryPointPath ) )
223+ . toString ( )
224+ . replace ( '{{WORKBENCH_WEB_CONFIGURATION}}' , escapeQuote ( JSON . stringify ( workbenchConfig ) ) ) ;
225+
226+ resp . writeHead ( 200 , {
227+ 'Content-Type' : 'text/html'
228+ } ) ;
229+ return resp . end ( entryPointContent ) ;
205230}
206231
207232interface ServerParsedArgs extends NativeParsedArgs {
@@ -558,6 +583,8 @@ export async function main(options: IServerOptions): Promise<void> {
558583 const requestService = accessor . get ( IRequestService ) ;
559584 channelServer . registerChannel ( 'request' , new RequestChannel ( requestService ) ) ;
560585
586+ const environmentService = accessor . get ( INativeEnvironmentService ) ;
587+
561588 // Delay creation of spdlog for perf reasons (https://github.com/microsoft/vscode/issues/72906)
562589 bufferLogService . logger = new SpdLogLogger ( 'main' , join ( environmentService . logsPath , `${ RemoteExtensionLogFileName } .log` ) , true , bufferLogService . getLevel ( ) ) ;
563590
@@ -588,7 +615,7 @@ export async function main(options: IServerOptions): Promise<void> {
588615
589616 //#region static
590617 if ( pathname === '/' ) {
591- return serveFile ( logService , req , res , devMode ? options . mainDev || WEB_MAIN_DEV : options . main || WEB_MAIN ) ;
618+ return handleRoot ( req , res , devMode ? options . mainDev || WEB_MAIN_DEV : options . main || WEB_MAIN , environmentService ) ;
592619 }
593620 if ( pathname === '/manifest.json' ) {
594621 res . writeHead ( 200 , { 'Content-Type' : 'application/json' } ) ;
@@ -906,7 +933,7 @@ export async function main(options: IServerOptions): Promise<void> {
906933 }
907934 server . listen ( port , '0.0.0.0' , ( ) => {
908935 const { address, port } = server . address ( ) as net . AddressInfo ;
909- logService . info ( `Web UI available at https ://${ address } :${ port } ` ) ;
936+ logService . info ( `Web UI available at http ://${ address } :${ port } ` ) ;
910937 } ) ;
911938 } ) ;
912939}
0 commit comments