@@ -5,6 +5,7 @@ import * as ReactDOMServer from "react-dom/server"
5
5
import App from "../../browser/app"
6
6
import { HttpCode , HttpError } from "../../common/http"
7
7
import { Options } from "../../common/util"
8
+ import { Vscode } from "../api/server"
8
9
import { HttpProvider , HttpResponse , Route } from "../http"
9
10
10
11
/**
@@ -21,39 +22,40 @@ export class MainHttpProvider extends HttpProvider {
21
22
return response
22
23
}
23
24
25
+ case "/vscode" :
24
26
case "/" : {
25
27
if ( route . requestPath !== "/index.html" ) {
26
28
throw new HttpError ( "Not found" , HttpCode . NotFound )
27
29
}
30
+
28
31
const options : Options = {
29
32
authed : ! ! this . authenticated ( request ) ,
30
33
basePath : this . base ( route ) ,
31
34
logLevel : logger . level ,
32
35
}
33
36
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
42
40
}
43
41
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 )
51
43
}
52
44
}
53
45
54
46
return undefined
55
47
}
56
48
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
+
57
59
public async handleWebSocket ( ) : Promise < undefined > {
58
60
return undefined
59
61
}
0 commit comments