Oprava URL pro websockety
This commit is contained in:
parent
1c1a8b7111
commit
839f51d8a3
@ -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!
|
||||
|
Loading…
x
Reference in New Issue
Block a user