jonboirama commited on
Commit
674f35f
·
unverified ·
1 Parent(s): b180108

fix: prefer explicit public gateway websocket url (#325)

Browse files
src/app/api/gateways/connect/route.ts CHANGED
@@ -174,9 +174,14 @@ export async function POST(request: NextRequest) {
174
  return NextResponse.json({ error: 'Gateway not found' }, { status: 404 })
175
  }
176
 
 
 
 
 
 
177
  // When gateway host is localhost but the browser is remote (e.g. Tailscale),
178
  // resolve the correct browser-accessible WebSocket URL.
179
- const remoteUrl = resolveRemoteGatewayUrl(gateway, request)
180
  const ws_url = remoteUrl || buildGatewayWebSocketUrl({
181
  host: gateway.host,
182
  port: gateway.port,
 
174
  return NextResponse.json({ error: 'Gateway not found' }, { status: 404 })
175
  }
176
 
177
+ // Prefer an explicitly configured browser WebSocket URL when provided.
178
+ // This is required for reverse-proxy setups where the browser-facing gateway
179
+ // lives on a different host/path than the server-side localhost gateway.
180
+ const explicitBrowserWsUrl = String(process.env.NEXT_PUBLIC_GATEWAY_URL || '').trim()
181
+
182
  // When gateway host is localhost but the browser is remote (e.g. Tailscale),
183
  // resolve the correct browser-accessible WebSocket URL.
184
+ const remoteUrl = explicitBrowserWsUrl || resolveRemoteGatewayUrl(gateway, request)
185
  const ws_url = remoteUrl || buildGatewayWebSocketUrl({
186
  host: gateway.host,
187
  port: gateway.port,