Add new frontend - fix 4

This commit is contained in:
Urtzi Alfaro
2025-07-22 09:42:06 +02:00
parent 6d5dea31ac
commit 52232815a2

View File

@@ -214,9 +214,16 @@ class WebSocketManager extends EventEmitter {
}
private getWebSocketBaseUrl(): string {
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
const host = process.env.REACT_APP_WS_URL || window.location.host;
return `${protocol}//${host}/ws`;
if (typeof window !== 'undefined') { // Check if window is defined
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
const host = process.env.REACT_APP_WS_URL || window.location.host;
return `${protocol}//${host}/ws`;
} else {
// Provide a fallback for server-side or non-browser environments
// You might want to get this from environment variables or a config file
// depending on your setup.
return process.env.REACT_APP_WS_URL || 'ws://localhost:3000/ws';
}
}
// Get connection status