@@ -5,11 +5,12 @@ import { CliMessage } from "../../lib/vscode/src/vs/server/ipc"
5
5
import { ApiHttpProvider } from "./app/api"
6
6
import { DashboardHttpProvider } from "./app/dashboard"
7
7
import { LoginHttpProvider } from "./app/login"
8
+ import { ProxyHttpProvider } from "./app/proxy"
8
9
import { StaticHttpProvider } from "./app/static"
9
10
import { UpdateHttpProvider } from "./app/update"
10
11
import { VscodeHttpProvider } from "./app/vscode"
11
12
import { Args , optionDescriptions , parse } from "./cli"
12
- import { AuthType , HttpServer } from "./http"
13
+ import { AuthType , HttpServer , HttpServerOptions } from "./http"
13
14
import { SshProvider } from "./ssh/server"
14
15
import { generateCertificate , generatePassword , generateSshHostKey , hash , open } from "./util"
15
16
import { ipcMain , wrap } from "./wrapper"
@@ -36,42 +37,31 @@ const main = async (args: Args): Promise<void> => {
36
37
const originalPassword = auth === AuthType . Password && ( process . env . PASSWORD || ( await generatePassword ( ) ) )
37
38
38
39
// Spawn the main HTTP server.
39
- const options = {
40
+ const options : HttpServerOptions = {
40
41
auth,
41
- cert : args . cert ? args . cert . value : undefined ,
42
- certKey : args [ "cert-key" ] ,
43
- sshHostKey : args [ "ssh-host-key" ] ,
44
42
commit,
45
43
host : args . host || ( args . auth === AuthType . Password && typeof args . cert !== "undefined" ? "0.0.0.0" : "localhost" ) ,
46
44
password : originalPassword ? hash ( originalPassword ) : undefined ,
47
45
port : typeof args . port !== "undefined" ? args . port : process . env . PORT ? parseInt ( process . env . PORT , 10 ) : 8080 ,
46
+ proxyDomains : args [ "proxy-domain" ] ,
48
47
socket : args . socket ,
48
+ ...( args . cert && ! args . cert . value
49
+ ? await generateCertificate ( )
50
+ : {
51
+ cert : args . cert && args . cert . value ,
52
+ certKey : args [ "cert-key" ] ,
53
+ } ) ,
49
54
}
50
55
51
- if ( ! options . cert && args . cert ) {
52
- const { cert, certKey } = await generateCertificate ( )
53
- options . cert = cert
54
- options . certKey = certKey
55
- } else if ( args . cert && ! args [ "cert-key" ] ) {
56
+ if ( options . cert && ! options . certKey ) {
56
57
throw new Error ( "--cert-key is missing" )
57
58
}
58
59
59
- if ( ! args [ "disable-ssh" ] ) {
60
- if ( ! options . sshHostKey && typeof options . sshHostKey !== "undefined" ) {
61
- throw new Error ( "--ssh-host-key cannot be blank" )
62
- } else if ( ! options . sshHostKey ) {
63
- try {
64
- options . sshHostKey = await generateSshHostKey ( )
65
- } catch ( error ) {
66
- logger . error ( "Unable to start SSH server" , field ( "error" , error . message ) )
67
- }
68
- }
69
- }
70
-
71
60
const httpServer = new HttpServer ( options )
72
61
const vscode = httpServer . registerHttpProvider ( "/" , VscodeHttpProvider , args )
73
62
const api = httpServer . registerHttpProvider ( "/api" , ApiHttpProvider , httpServer , vscode , args [ "user-data-dir" ] )
74
63
const update = httpServer . registerHttpProvider ( "/update" , UpdateHttpProvider , ! args [ "disable-updates" ] )
64
+ httpServer . registerHttpProvider ( "/proxy" , ProxyHttpProvider )
75
65
httpServer . registerHttpProvider ( "/login" , LoginHttpProvider )
76
66
httpServer . registerHttpProvider ( "/static" , StaticHttpProvider )
77
67
httpServer . registerHttpProvider ( "/dashboard" , DashboardHttpProvider , api , update )
@@ -84,7 +74,7 @@ const main = async (args: Args): Promise<void> => {
84
74
85
75
if ( auth === AuthType . Password && ! process . env . PASSWORD ) {
86
76
logger . info ( ` - Password is ${ originalPassword } ` )
87
- logger . info ( " - To use your own password, set the PASSWORD environment variable" )
77
+ logger . info ( " - To use your own password set the PASSWORD environment variable" )
88
78
if ( ! args . auth ) {
89
79
logger . info ( " - To disable use `--auth none`" )
90
80
}
@@ -96,19 +86,33 @@ const main = async (args: Args): Promise<void> => {
96
86
97
87
if ( httpServer . protocol === "https" ) {
98
88
logger . info (
99
- typeof args . cert === "string"
89
+ args . cert && args . cert . value
100
90
? ` - Using provided certificate and key for HTTPS`
101
91
: ` - Using generated certificate and key for HTTPS` ,
102
92
)
103
93
} else {
104
94
logger . info ( " - Not serving HTTPS" )
105
95
}
106
96
97
+ if ( httpServer . proxyDomains . size > 0 ) {
98
+ logger . info ( ` - Proxying the following domain${ httpServer . proxyDomains . size === 1 ? "" : "s" } :` )
99
+ httpServer . proxyDomains . forEach ( ( domain ) => logger . info ( ` - *.${ domain } ` ) )
100
+ }
101
+
107
102
logger . info ( `Automatic updates are ${ update . enabled ? "enabled" : "disabled" } ` )
108
103
104
+ let sshHostKey = args [ "ssh-host-key" ]
105
+ if ( ! args [ "disable-ssh" ] && ! sshHostKey ) {
106
+ try {
107
+ sshHostKey = await generateSshHostKey ( )
108
+ } catch ( error ) {
109
+ logger . error ( "Unable to start SSH server" , field ( "error" , error . message ) )
110
+ }
111
+ }
112
+
109
113
let sshPort : number | undefined
110
- if ( ! args [ "disable-ssh" ] && options . sshHostKey ) {
111
- const sshProvider = httpServer . registerHttpProvider ( "/ssh" , SshProvider , options . sshHostKey as string )
114
+ if ( ! args [ "disable-ssh" ] && sshHostKey ) {
115
+ const sshProvider = httpServer . registerHttpProvider ( "/ssh" , SshProvider , sshHostKey )
112
116
try {
113
117
sshPort = await sshProvider . listen ( )
114
118
} catch ( error ) {
@@ -118,6 +122,7 @@ const main = async (args: Args): Promise<void> => {
118
122
119
123
if ( typeof sshPort !== "undefined" ) {
120
124
logger . info ( `SSH server listening on localhost:${ sshPort } ` )
125
+ logger . info ( " - To disable use `--disable-ssh`" )
121
126
} else {
122
127
logger . info ( "SSH server disabled" )
123
128
}
0 commit comments