frontend: getting correct hostname and port

This commit is contained in:
Mose Müller
2023-08-02 12:06:20 +02:00
parent bc0ae0196d
commit 49d7ea30ef
3 changed files with 13 additions and 7 deletions

View File

@@ -1,6 +1,10 @@
import { io } from 'socket.io-client';
const URL = 'ws://localhost:8001/';
// process.env.NODE_ENV === 'production' ? undefined : 'ws://localhost:8001/ws';
export const hostname =
process.env.NODE_ENV === 'development' ? `localhost` : window.location.hostname;
export const port =
process.env.NODE_ENV === 'development' ? 8001 : window.location.port;
const URL = `ws://${hostname}:${port}/`;
console.debug('Websocket: ', URL);
export const socket = io(URL, { path: '/ws/socket.io', transports: ['websocket'] });