@@ -5,6 +5,7 @@ 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"
@@ -35,22 +36,13 @@ const main = async (args: Args): Promise<void> => {
35
36
const auth = args . auth || AuthType . Password
36
37
const originalPassword = auth === AuthType . Password && ( process . env . PASSWORD || ( await generatePassword ( ) ) )
37
38
38
- /**
39
- * Domains can be in the form `coder.com` or `*.coder.com`. Either way,
40
- * `[number].coder.com` will be proxied to `number`.
41
- */
42
- const normalizeProxyDomains = ( domains ?: string [ ] ) : string [ ] => {
43
- return domains ? domains . map ( ( d ) => d . replace ( / ^ \* \. / , "" ) ) . filter ( ( d , i ) => domains . indexOf ( d ) === i ) : [ ]
44
- }
45
-
46
39
// Spawn the main HTTP server.
47
40
const options : HttpServerOptions = {
48
41
auth,
49
42
commit,
50
43
host : args . host || ( args . auth === AuthType . Password && typeof args . cert !== "undefined" ? "0.0.0.0" : "localhost" ) ,
51
44
password : originalPassword ? hash ( originalPassword ) : undefined ,
52
45
port : typeof args . port !== "undefined" ? args . port : process . env . PORT ? parseInt ( process . env . PORT , 10 ) : 8080 ,
53
- proxyDomains : normalizeProxyDomains ( args [ "proxy-domain" ] ) ,
54
46
socket : args . socket ,
55
47
...( args . cert && ! args . cert . value
56
48
? await generateCertificate ( )
@@ -64,13 +56,23 @@ const main = async (args: Args): Promise<void> => {
64
56
throw new Error ( "--cert-key is missing" )
65
57
}
66
58
59
+ /**
60
+ * Domains can be in the form `coder.com` or `*.coder.com`. Either way,
61
+ * `[number].coder.com` will be proxied to `number`.
62
+ */
63
+ const proxyDomains = args [ "proxy-domain" ]
64
+ ? args [ "proxy-domain" ] . map ( ( d ) => d . replace ( / ^ \* \. / , "" ) ) . filter ( ( d , i , arr ) => arr . indexOf ( d ) === i )
65
+ : [ ]
66
+
67
67
const httpServer = new HttpServer ( options )
68
68
const vscode = httpServer . registerHttpProvider ( "/" , VscodeHttpProvider , args )
69
69
const api = httpServer . registerHttpProvider ( "/api" , ApiHttpProvider , httpServer , vscode , args [ "user-data-dir" ] )
70
70
const update = httpServer . registerHttpProvider ( "/update" , UpdateHttpProvider , ! args [ "disable-updates" ] )
71
+ const proxy = httpServer . registerHttpProvider ( "/proxy" , ProxyHttpProvider , proxyDomains )
71
72
httpServer . registerHttpProvider ( "/login" , LoginHttpProvider )
72
73
httpServer . registerHttpProvider ( "/static" , StaticHttpProvider )
73
74
httpServer . registerHttpProvider ( "/dashboard" , DashboardHttpProvider , api , update )
75
+ httpServer . registerProxy ( proxy )
74
76
75
77
ipcMain ( ) . onDispose ( ( ) => httpServer . dispose ( ) )
76
78
@@ -100,13 +102,11 @@ const main = async (args: Args): Promise<void> => {
100
102
logger . info ( " - Not serving HTTPS" )
101
103
}
102
104
103
- if ( options . proxyDomains && options . proxyDomains . length === 1 ) {
104
- logger . info ( ` - Proxying *.${ options . proxyDomains [ 0 ] } ` )
105
- } else if ( options . proxyDomains && options . proxyDomains . length > 1 ) {
105
+ if ( proxyDomains . length === 1 ) {
106
+ logger . info ( ` - Proxying *.${ proxyDomains [ 0 ] } ` )
107
+ } else if ( proxyDomains && proxyDomains . length > 1 ) {
106
108
logger . info ( " - Proxying the following domains:" )
107
- options . proxyDomains . forEach ( ( domain ) => {
108
- logger . info ( ` - *.${ domain } ` )
109
- } )
109
+ proxyDomains . forEach ( ( domain ) => logger . info ( ` - *.${ domain } ` ) )
110
110
}
111
111
112
112
logger . info ( `Automatic updates are ${ update . enabled ? "enabled" : "disabled" } ` )
0 commit comments