From e56203b6a8cc64f127f89e077e2120ffb2c3d5a3 Mon Sep 17 00:00:00 2001 From: Nyk <0xnykcd@googlemail.com> Date: Sun, 22 Mar 2026 13:08:40 +0700 Subject: [PATCH] fix: Settings panel now respects NEXT_PUBLIC_GATEWAY_URL (#468) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The multi-gateway panel was constructing WebSocket URLs client-side using buildGatewayWebSocketUrl() with the gateway's DB host/port, ignoring the server-side URL resolution that respects NEXT_PUBLIC_GATEWAY_URL, Tailscale Serve, and reverse-proxy configs. - Remove client-side buildGatewayWebSocketUrl fallback in connectTo() — server's /api/gateways/connect already handles all URL resolution - Simplify gatewayMatchesConnection() to use direct host/port string matching without constructing a derived WS URL - Remove unused buildGatewayWebSocketUrl import Fixes #468 --- src/components/panels/multi-gateway-panel.tsx | 26 ++++++------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/components/panels/multi-gateway-panel.tsx b/src/components/panels/multi-gateway-panel.tsx index caf65c5..9f4c191 100644 --- a/src/components/panels/multi-gateway-panel.tsx +++ b/src/components/panels/multi-gateway-panel.tsx @@ -5,7 +5,6 @@ import { useTranslations } from 'next-intl' import { Button } from '@/components/ui/button' import { useMissionControl } from '@/store' import { useWebSocket } from '@/lib/websocket' -import { buildGatewayWebSocketUrl } from '@/lib/gateway-url' interface Gateway { id: number @@ -130,19 +129,11 @@ export function MultiGatewayPanel() { const normalizedConn = url.toLowerCase() const normalizedHost = String(gw.host || '').toLowerCase() - if (normalizedHost && normalizedConn.includes(normalizedHost)) return true + // Skip localhost matching — server rewrites localhost to browser hostname, + // so the connection URL won't contain "127.0.0.1". Port matching handles it. + if (normalizedHost && normalizedHost !== '127.0.0.1' && normalizedHost !== 'localhost' && normalizedConn.includes(normalizedHost)) return true if (normalizedConn.includes(`:${gw.port}`)) return true - - try { - const derivedWs = buildGatewayWebSocketUrl({ - host: gw.host, - port: gw.port, - browserProtocol: window.location.protocol, - }).toLowerCase() - return normalizedConn.includes(derivedWs) - } catch { - return false - } + return false }, [connection.url]) const shouldShowConnectionSummary = @@ -179,11 +170,10 @@ export function MultiGatewayPanel() { if (!res.ok) return const payload = await res.json() - const wsUrl = String(payload?.ws_url || buildGatewayWebSocketUrl({ - host: gw.host, - port: gw.port, - browserProtocol: window.location.protocol, - })) + // Use server-resolved URL only — it respects NEXT_PUBLIC_GATEWAY_URL, + // Tailscale Serve, and reverse-proxy configurations. + const wsUrl = payload?.ws_url + if (!wsUrl) return const token = String(payload?.token || '') connect(wsUrl, token) } catch {