fix: websocket connect failed in prod env

This commit is contained in:
Junyan Qin
2025-12-02 17:41:31 +08:00
parent 08c0677de9
commit 24f779ff95

View File

@@ -79,8 +79,10 @@ export class WebSocketClient {
// 构建WebSocket URL
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
// extract host from process.env.NEXT_PUBLIC_API_BASE_URL
// 如果环境变量未定义,使用当前页面的 host (适配生产环境)
const host =
process.env.NEXT_PUBLIC_API_BASE_URL?.split('://')[1] || '';
process.env.NEXT_PUBLIC_API_BASE_URL?.split('://')[1] ||
window.location.host;
const url = `${protocol}//${host}/api/v1/pipelines/${this.pipelineId}/ws/connect?session_type=${this.sessionType}`;
this.ws = new WebSocket(url);