mirror of
https://github.com/OpenBMB/ChatDev.git
synced 2026-04-25 11:18:06 +00:00
fix: fix websocket connection issue in BatchRunView
This commit is contained in:
parent
83a7c36f3b
commit
b3a22b4fbd
@ -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
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user