@@ -5,6 +5,7 @@ import * as ReactDOMServer from "react-dom/server"
55import App from "../../browser/app"
66import { HttpCode , HttpError } from "../../common/http"
77import { Options } from "../../common/util"
8+ import { Vscode } from "../api/server"
89import { HttpProvider , HttpResponse , Route } from "../http"
910
1011/**
@@ -21,39 +22,40 @@ export class MainHttpProvider extends HttpProvider {
2122 return response
2223 }
2324
25+ case "/vscode" :
2426 case "/" : {
2527 if ( route . requestPath !== "/index.html" ) {
2628 throw new HttpError ( "Not found" , HttpCode . NotFound )
2729 }
30+
2831 const options : Options = {
2932 authed : ! ! this . authenticated ( request ) ,
3033 basePath : this . base ( route ) ,
3134 logLevel : logger . level ,
3235 }
3336
34- if ( options . authed ) {
35- // TEMP: Auto-load VS Code for now. In future versions we'll need to check
36- // the URL for the appropriate application to load, if any.
37- options . app = {
38- name : "VS Code" ,
39- path : "/" ,
40- embedPath : "/vscode-embed" ,
41- }
37+ // TODO: Load other apps based on the URL as well.
38+ if ( route . base === Vscode . path && options . authed ) {
39+ options . app = Vscode
4240 }
4341
44- const response = await this . getUtf8Resource ( this . rootPath , "src/browser/index.html" )
45- response . content = response . content
46- . replace ( / { { COMMIT} } / g, this . options . commit )
47- . replace ( / { { BASE} } / g, this . base ( route ) )
48- . replace ( / " { { O P T I O N S } } " / g, `'${ JSON . stringify ( options ) } '` )
49- . replace ( / { { COMPONENT} } / g, ReactDOMServer . renderToString ( < App options = { options } /> ) )
50- return response
42+ return this . getRoot ( route , options )
5143 }
5244 }
5345
5446 return undefined
5547 }
5648
49+ public async getRoot ( route : Route , options : Options ) : Promise < HttpResponse > {
50+ const response = await this . getUtf8Resource ( this . rootPath , "src/browser/index.html" )
51+ response . content = response . content
52+ . replace ( / { { COMMIT} } / g, this . options . commit )
53+ . replace ( / { { BASE} } / g, this . base ( route ) )
54+ . replace ( / " { { O P T I O N S } } " / g, `'${ JSON . stringify ( options ) } '` )
55+ . replace ( / { { COMPONENT} } / g, ReactDOMServer . renderToString ( < App options = { options } /> ) )
56+ return response
57+ }
58+
5759 public async handleWebSocket ( ) : Promise < undefined > {
5860 return undefined
5961 }
0 commit comments