From e97d5634bffc3876cb5580fdbd59d9f6e8b2d2fa Mon Sep 17 00:00:00 2001 From: Mihai Parparita Date: Mon, 26 Sep 2022 13:50:26 -0700 Subject: [PATCH] control/controlhttp: use custom port for non-localhost JS noise client connections Control may not be bound to (just) localhost when sharing dev servers, allow the Wasm client to connect to it in that case too. Signed-off-by: Mihai Parparita --- control/controlhttp/client_js.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/control/controlhttp/client_js.go b/control/controlhttp/client_js.go index 3b1ad4151..d31cae731 100644 --- a/control/controlhttp/client_js.go +++ b/control/controlhttp/client_js.go @@ -29,9 +29,11 @@ func (d *Dialer) Dial(ctx context.Context) (*controlbase.Conn, error) { wsScheme := "wss" host := d.Hostname - if host == "localhost" { + // If using a custom control server (on a non-standard port), prefer that. + // This mirrors the port selection in newNoiseClient from noise.go. + if d.HTTPPort != "" && d.HTTPPort != "80" && d.HTTPSPort == "443" { wsScheme = "ws" - host = net.JoinHostPort(host, strDef(d.HTTPPort, "80")) + host = net.JoinHostPort(host, d.HTTPPort) } wsURL := &url.URL{ Scheme: wsScheme,