@@ -169,6 +169,11 @@ function getMediaMime(forPath: string): string | undefined {
169
169
return mapExtToMediaMimes . get ( ext . toLowerCase ( ) ) ;
170
170
}
171
171
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
+
172
177
async function serveFile ( logService : ILogService , req : http . IncomingMessage , res : http . ServerResponse , filePath : string , responseHeaders : http . OutgoingHttpHeaders = { } ) {
173
178
try {
174
179
@@ -199,9 +204,29 @@ async function serveFile(logService: ILogService, req: http.IncomingMessage, res
199
204
}
200
205
}
201
206
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 ) ;
205
230
}
206
231
207
232
interface ServerParsedArgs extends NativeParsedArgs {
@@ -558,6 +583,8 @@ export async function main(options: IServerOptions): Promise<void> {
558
583
const requestService = accessor . get ( IRequestService ) ;
559
584
channelServer . registerChannel ( 'request' , new RequestChannel ( requestService ) ) ;
560
585
586
+ const environmentService = accessor . get ( INativeEnvironmentService ) ;
587
+
561
588
// Delay creation of spdlog for perf reasons (https://github.com/microsoft/vscode/issues/72906)
562
589
bufferLogService . logger = new SpdLogLogger ( 'main' , join ( environmentService . logsPath , `${ RemoteExtensionLogFileName } .log` ) , true , bufferLogService . getLevel ( ) ) ;
563
590
@@ -588,7 +615,7 @@ export async function main(options: IServerOptions): Promise<void> {
588
615
589
616
//#region static
590
617
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 ) ;
592
619
}
593
620
if ( pathname === '/manifest.json' ) {
594
621
res . writeHead ( 200 , { 'Content-Type' : 'application/json' } ) ;
@@ -906,7 +933,7 @@ export async function main(options: IServerOptions): Promise<void> {
906
933
}
907
934
server . listen ( port , '0.0.0.0' , ( ) => {
908
935
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 } ` ) ;
910
937
} ) ;
911
938
} ) ;
912
939
}
0 commit comments