@@ -5,6 +5,7 @@ import { CliMessage } from "../../lib/vscode/src/vs/server/ipc"
55import { ApiHttpProvider } from "./app/api"
66import { DashboardHttpProvider } from "./app/dashboard"
77import { LoginHttpProvider } from "./app/login"
8+ import { ProxyHttpProvider } from "./app/proxy"
89import { StaticHttpProvider } from "./app/static"
910import { UpdateHttpProvider } from "./app/update"
1011import { VscodeHttpProvider } from "./app/vscode"
@@ -35,22 +36,13 @@ const main = async (args: Args): Promise<void> => {
3536 const auth = args . auth || AuthType . Password
3637 const originalPassword = auth === AuthType . Password && ( process . env . PASSWORD || ( await generatePassword ( ) ) )
3738
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-
4639 // Spawn the main HTTP server.
4740 const options : HttpServerOptions = {
4841 auth,
4942 commit,
5043 host : args . host || ( args . auth === AuthType . Password && typeof args . cert !== "undefined" ? "0.0.0.0" : "localhost" ) ,
5144 password : originalPassword ? hash ( originalPassword ) : undefined ,
5245 port : typeof args . port !== "undefined" ? args . port : process . env . PORT ? parseInt ( process . env . PORT , 10 ) : 8080 ,
53- proxyDomains : normalizeProxyDomains ( args [ "proxy-domain" ] ) ,
5446 socket : args . socket ,
5547 ...( args . cert && ! args . cert . value
5648 ? await generateCertificate ( )
@@ -64,13 +56,23 @@ const main = async (args: Args): Promise<void> => {
6456 throw new Error ( "--cert-key is missing" )
6557 }
6658
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+
6767 const httpServer = new HttpServer ( options )
6868 const vscode = httpServer . registerHttpProvider ( "/" , VscodeHttpProvider , args )
6969 const api = httpServer . registerHttpProvider ( "/api" , ApiHttpProvider , httpServer , vscode , args [ "user-data-dir" ] )
7070 const update = httpServer . registerHttpProvider ( "/update" , UpdateHttpProvider , ! args [ "disable-updates" ] )
71+ const proxy = httpServer . registerHttpProvider ( "/proxy" , ProxyHttpProvider , proxyDomains )
7172 httpServer . registerHttpProvider ( "/login" , LoginHttpProvider )
7273 httpServer . registerHttpProvider ( "/static" , StaticHttpProvider )
7374 httpServer . registerHttpProvider ( "/dashboard" , DashboardHttpProvider , api , update )
75+ httpServer . registerProxy ( proxy )
7476
7577 ipcMain ( ) . onDispose ( ( ) => httpServer . dispose ( ) )
7678
@@ -100,13 +102,11 @@ const main = async (args: Args): Promise<void> => {
100102 logger . info ( " - Not serving HTTPS" )
101103 }
102104
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 ) {
106108 logger . info ( " - Proxying the following domains:" )
107- options . proxyDomains . forEach ( ( domain ) => {
108- logger . info ( ` - *.${ domain } ` )
109- } )
109+ proxyDomains . forEach ( ( domain ) => logger . info ( ` - *.${ domain } ` ) )
110110 }
111111
112112 logger . info ( `Automatic updates are ${ update . enabled ? "enabled" : "disabled" } ` )
0 commit comments