fix: fix websocket connection issue in BatchRunView

This commit is contained in:
Petar Zivkovic 2026-02-09 16:40:34 +01:00
parent 83a7c36f3b
commit b3a22b4fbd

View File

@ -969,10 +969,24 @@ const establishWebSocketConnection = () => {
return return
} }
const baseUrl = import.meta.env.VITE_API_BASE_URL || 'http://localhost:8000' const apiBase = import.meta.env.VITE_API_BASE_URL || ''
const wsProtocol = baseUrl.startsWith('https') ? 'wss:' : 'ws:' // Defaults: same-origin (works with Vite dev proxy)
const urlObj = new URL(baseUrl) const defaultScheme = window.location.protocol === 'https:' ? 'wss:' : 'ws:'
const wsUrl = `${wsProtocol}//${urlObj.host}/ws` let scheme = defaultScheme
let host = window.location.host
// In production, prefer explicit API base if provided
if (!import.meta.env.DEV && apiBase) {
try {
const api = new URL(apiBase, window.location.origin)
scheme = api.protocol === 'https:' ? 'wss:' : 'ws:'
host = api.host
} catch {
// keep defaults
}
}
const wsUrl = `${scheme}//${host}/ws`
const socket = new WebSocket(wsUrl) const socket = new WebSocket(wsUrl)
ws = socket ws = socket