diff --git a/frontend/src/api/websocket.ts b/frontend/src/api/websocket.ts index 9f13238..69b03a6 100644 --- a/frontend/src/api/websocket.ts +++ b/frontend/src/api/websocket.ts @@ -108,3 +108,19 @@ export class WebSocketClient { // Create singleton instance export const wsClient = new WebSocketClient(); +// Export helper to get WS URL +export const getWebSocketUrl = (): string => { + // Если задан VITE_WS_URL, используем его + if (import.meta.env.VITE_WS_URL) { + return import.meta.env.VITE_WS_URL; + } + + // Иначе определяем автоматически на основе текущего location + const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; + const host = window.location.host; + return `${protocol}//${host}`; +}; + +// Export WS_URL for direct usage +export const WS_URL = `${getWebSocketUrl()}/ws/reviews`; +