From 839f51d8a36b5758e2b5c90066e8fec78901b681 Mon Sep 17 00:00:00 2001 From: Martin Berka <martin.berka@radbuza.net> Date: Sun, 23 Jul 2023 00:04:53 +0200 Subject: [PATCH] Oprava URL pro websockety --- client/src/context/socket.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/client/src/context/socket.js b/client/src/context/socket.js index f5889b9..fd70419 100644 --- a/client/src/context/socket.js +++ b/client/src/context/socket.js @@ -1,11 +1,17 @@ import React from 'react'; import socketio from "socket.io-client"; -import { getBaseUrl } from "../Utils"; -// Hack pro socket.io, který si s tečkou neumí poradit -const socketUrl = getBaseUrl() === '.' ? '/' : getBaseUrl(); -// Záměrně omezeno jen na websocket, aby se případně odhalilo chybné nastavení proxy serveru -export const socket = socketio.connect(socketUrl, { transports: ["websocket"] }); +let socketUrl; +let socketPath; +if (process.env.NODE_ENV === 'development') { + socketUrl = `http://localhost:3001`; + socketPath = undefined; +} else { + socketUrl = `${window.location.host}`; + socketPath = `${window.location.pathname}socket.io`; +} + +export const socket = socketio.connect(socketUrl, { path: socketPath, transports: ["websocket"] }); export const SocketContext = React.createContext(); // Konstanty websocket eventů, musí odpovídat těm na serveru!