Refactor socket initialization for development and production environments
This commit is contained in:
parent
fb68e6d43a
commit
64517450f7
@ -13,7 +13,13 @@ function App() {
|
||||
const [playerSocket, setPlayerSocket] = useState();
|
||||
const [redirect, setRedirect] = useState();
|
||||
useEffect(() => {
|
||||
const socket = io(`http://${window.location.hostname}:8080`, { withCredentials: true });
|
||||
let socket;
|
||||
if(process.env.NODE_ENV !== 'production') {
|
||||
socket = io(`http://${window.location.hostname}:8080`, { withCredentials: true });
|
||||
} else {
|
||||
socket = io(`${window.location.protocol}//${window.location.host}`, { withCredentials: true });
|
||||
}
|
||||
|
||||
socket.on('player:data', data => {
|
||||
data = JSON.parse(data);
|
||||
setPlayerData(data);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user