diff --git a/src/components/LoginScreen.tsx b/src/components/LoginScreen.tsx index 0119731..24eca4e 100644 --- a/src/components/LoginScreen.tsx +++ b/src/components/LoginScreen.tsx @@ -12,7 +12,18 @@ interface Props { function getInitialUrl(): string { const stored = getStoredCredentials(); if (stored) return stored.url; - return import.meta.env.VITE_GATEWAY_WS_URL || `ws://${window.location.hostname}:18789`; + if (import.meta.env.VITE_GATEWAY_WS_URL) return import.meta.env.VITE_GATEWAY_WS_URL; + const protocol = window.location.protocol === 'https:' ? 'wss' : 'ws'; + const host = window.location.hostname; + // When served over HTTPS, assume gateway is on a sibling subdomain (e.g. marlbot-gw.example.com) + if (protocol === 'wss') { + const parts = host.split('.'); + if (parts.length >= 2) { + parts[0] = parts[0] + '-gw'; + return `${protocol}://${parts.join('.')}`; + } + } + return `${protocol}://${host}:18789`; } function getInitialToken(): string {