mirror of
https://github.com/coder/coder.git
synced 2025-07-09 11:45:56 +00:00
feat: Let port-forwarding support custom http(s) port (#5084)
This commit is contained in:
@ -124,6 +124,9 @@ func (api *API) workspaceAgentMetadata(rw http.ResponseWriter, r *http.Request)
|
||||
workspace.Name,
|
||||
owner.Username,
|
||||
))
|
||||
if api.AccessURL.Port() != "" {
|
||||
vscodeProxyURI += fmt.Sprintf(":%s", api.AccessURL.Port())
|
||||
}
|
||||
|
||||
httpapi.Write(ctx, rw, http.StatusOK, codersdk.WorkspaceAgentMetadata{
|
||||
Apps: convertApps(dbApps),
|
||||
|
@ -40,8 +40,13 @@ const (
|
||||
)
|
||||
|
||||
func (api *API) appHost(rw http.ResponseWriter, r *http.Request) {
|
||||
host := api.AppHostname
|
||||
if api.AccessURL.Port() != "" {
|
||||
host += fmt.Sprintf(":%s", api.AccessURL.Port())
|
||||
}
|
||||
|
||||
httpapi.Write(r.Context(), rw, http.StatusOK, codersdk.GetAppHostResponse{
|
||||
Host: api.AppHostname,
|
||||
Host: host,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,8 @@ func TestGetAppHost(t *testing.T) {
|
||||
_ = coderdtest.CreateFirstUser(t, client)
|
||||
host, err = client.GetAppHost(ctx)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, c, host.Host)
|
||||
domain := strings.Split(host.Host, ":")[0]
|
||||
require.Equal(t, c, domain)
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -204,13 +205,17 @@ func createWorkspaceWithApps(t *testing.T, client *codersdk.Client, orgID uuid.U
|
||||
if appHost != "" {
|
||||
metadata, err := agentClient.WorkspaceAgentMetadata(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, fmt.Sprintf(
|
||||
proxyURL := fmt.Sprintf(
|
||||
"http://{{port}}--%s--%s--%s%s",
|
||||
proxyTestAgentName,
|
||||
workspace.Name,
|
||||
"testuser",
|
||||
strings.ReplaceAll(appHost, "*", ""),
|
||||
), metadata.VSCodePortProxyURI)
|
||||
)
|
||||
if client.URL.Port() != "" {
|
||||
proxyURL += fmt.Sprintf(":%s", client.URL.Port())
|
||||
}
|
||||
require.Equal(t, proxyURL, metadata.VSCodePortProxyURI)
|
||||
}
|
||||
agentCloser := agent.New(agent.Options{
|
||||
Client: agentClient,
|
||||
|
Reference in New Issue
Block a user