Skip to content

Commit 081fbef

Browse files
authored
fix: code-server path based forwarding, defer to code-server (#11759)
Do not attempt to construct a path based port forward url. Always defer to code server, as it has it's own proxy method.
1 parent 77a4792 commit 081fbef

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

agent/agentssh/agentssh.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,11 @@ func (s *Server) CreateCommand(ctx context.Context, script string, env []string)
681681

682682
// This adds the ports dialog to code-server that enables
683683
// proxying a port dynamically.
684-
cmd.Env = append(cmd.Env, fmt.Sprintf("VSCODE_PROXY_URI=%s", manifest.VSCodePortProxyURI))
684+
// If this is empty string, do not set anything. Code-server auto defaults
685+
// using its basepath to construct a path based port proxy.
686+
if manifest.VSCodePortProxyURI != "" {
687+
cmd.Env = append(cmd.Env, fmt.Sprintf("VSCODE_PROXY_URI=%s", manifest.VSCodePortProxyURI))
688+
}
685689

686690
// Hide Coder message on code-server's "Getting Started" page
687691
cmd.Env = append(cmd.Env, "CS_DISABLE_GETTING_STARTED_OVERRIDE=true")

coderd/agentapi/manifest.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,14 @@ func (a *ManifestAPI) GetManifest(ctx context.Context, _ *agentproto.GetManifest
150150
}
151151

152152
func vscodeProxyURI(app appurl.ApplicationURL, accessURL *url.URL, appHost string) string {
153-
// This will handle the ports from the accessURL or appHost.
154-
appHost = appurl.SubdomainAppHost(appHost, accessURL)
155-
// If there is no appHost, then we want to use the access url as the proxy uri.
153+
// Proxying by port only works for subdomains. If subdomain support is not
154+
// available, return an empty string.
156155
if appHost == "" {
157-
appHost = accessURL.Host
156+
return ""
158157
}
158+
159+
// This will handle the ports from the accessURL or appHost.
160+
appHost = appurl.SubdomainAppHost(appHost, accessURL)
159161
// Return the url with a scheme and any wildcards replaced with the app slug.
160162
return accessURL.Scheme + "://" + strings.ReplaceAll(appHost, "*", app.String())
161163
}

coderd/agentapi/manifest_internal_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,18 @@ func Test_vscodeProxyURI(t *testing.T) {
3535
Expected string
3636
}{
3737
{
38-
// No hostname proxies through the access url.
3938
Name: "NoHostname",
4039
AccessURL: coderAccessURL,
4140
AppHostname: "",
4241
App: basicApp,
43-
Expected: coderAccessURL.String(),
42+
Expected: "",
4443
},
4544
{
4645
Name: "NoHostnameAccessURLPort",
4746
AccessURL: accessURLWithPort,
4847
AppHostname: "",
4948
App: basicApp,
50-
Expected: accessURLWithPort.String(),
49+
Expected: "",
5150
},
5251
{
5352
Name: "Hostname",

0 commit comments

Comments
 (0)