Skip to content

Commit 5457dd0

Browse files
authored
feat: Let port-forwarding support custom http(s) port (#5084)
1 parent 2ec3b09 commit 5457dd0

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

coderd/workspaceagents.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ func (api *API) workspaceAgentMetadata(rw http.ResponseWriter, r *http.Request)
124124
workspace.Name,
125125
owner.Username,
126126
))
127+
if api.AccessURL.Port() != "" {
128+
vscodeProxyURI += fmt.Sprintf(":%s", api.AccessURL.Port())
129+
}
127130

128131
httpapi.Write(ctx, rw, http.StatusOK, codersdk.WorkspaceAgentMetadata{
129132
Apps: convertApps(dbApps),

coderd/workspaceapps.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,13 @@ const (
4040
)
4141

4242
func (api *API) appHost(rw http.ResponseWriter, r *http.Request) {
43+
host := api.AppHostname
44+
if api.AccessURL.Port() != "" {
45+
host += fmt.Sprintf(":%s", api.AccessURL.Port())
46+
}
47+
4348
httpapi.Write(r.Context(), rw, http.StatusOK, codersdk.GetAppHostResponse{
44-
Host: api.AppHostname,
49+
Host: host,
4550
})
4651
}
4752

coderd/workspaceapps_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ func TestGetAppHost(t *testing.T) {
6969
_ = coderdtest.CreateFirstUser(t, client)
7070
host, err = client.GetAppHost(ctx)
7171
require.NoError(t, err)
72-
require.Equal(t, c, host.Host)
72+
domain := strings.Split(host.Host, ":")[0]
73+
require.Equal(t, c, domain)
7374
})
7475
}
7576
}
@@ -204,13 +205,17 @@ func createWorkspaceWithApps(t *testing.T, client *codersdk.Client, orgID uuid.U
204205
if appHost != "" {
205206
metadata, err := agentClient.WorkspaceAgentMetadata(context.Background())
206207
require.NoError(t, err)
207-
require.Equal(t, fmt.Sprintf(
208+
proxyURL := fmt.Sprintf(
208209
"http://{{port}}--%s--%s--%s%s",
209210
proxyTestAgentName,
210211
workspace.Name,
211212
"testuser",
212213
strings.ReplaceAll(appHost, "*", ""),
213-
), metadata.VSCodePortProxyURI)
214+
)
215+
if client.URL.Port() != "" {
216+
proxyURL += fmt.Sprintf(":%s", client.URL.Port())
217+
}
218+
require.Equal(t, proxyURL, metadata.VSCodePortProxyURI)
214219
}
215220
agentCloser := agent.New(agent.Options{
216221
Client: agentClient,

0 commit comments

Comments
 (0)