fix: Settings panel now respects NEXT_PUBLIC_GATEWAY_URL (#468)

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
This commit is contained in:
Nyk 2026-03-22 13:08:40 +07:00
parent 34cbc351a1
commit e56203b6a8
1 changed files with 8 additions and 18 deletions

View File

@ -5,7 +5,6 @@ import { useTranslations } from 'next-intl'
import { Button } from '@/components/ui/button' import { Button } from '@/components/ui/button'
import { useMissionControl } from '@/store' import { useMissionControl } from '@/store'
import { useWebSocket } from '@/lib/websocket' import { useWebSocket } from '@/lib/websocket'
import { buildGatewayWebSocketUrl } from '@/lib/gateway-url'
interface Gateway { interface Gateway {
id: number id: number
@ -130,19 +129,11 @@ export function MultiGatewayPanel() {
const normalizedConn = url.toLowerCase() const normalizedConn = url.toLowerCase()
const normalizedHost = String(gw.host || '').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 if (normalizedConn.includes(`:${gw.port}`)) return true
return false
try {
const derivedWs = buildGatewayWebSocketUrl({
host: gw.host,
port: gw.port,
browserProtocol: window.location.protocol,
}).toLowerCase()
return normalizedConn.includes(derivedWs)
} catch {
return false
}
}, [connection.url]) }, [connection.url])
const shouldShowConnectionSummary = const shouldShowConnectionSummary =
@ -179,11 +170,10 @@ export function MultiGatewayPanel() {
if (!res.ok) return if (!res.ok) return
const payload = await res.json() const payload = await res.json()
const wsUrl = String(payload?.ws_url || buildGatewayWebSocketUrl({ // Use server-resolved URL only — it respects NEXT_PUBLIC_GATEWAY_URL,
host: gw.host, // Tailscale Serve, and reverse-proxy configurations.
port: gw.port, const wsUrl = payload?.ws_url
browserProtocol: window.location.protocol, if (!wsUrl) return
}))
const token = String(payload?.token || '') const token = String(payload?.token || '')
connect(wsUrl, token) connect(wsUrl, token)
} catch { } catch {