diff --git a/src/components/ControllerPage.vue b/src/components/ControllerPage.vue index 6c49391..e6bc1c6 100644 --- a/src/components/ControllerPage.vue +++ b/src/components/ControllerPage.vue @@ -312,7 +312,12 @@ export default { // Permette di specificare un host WebSocket alternativo via query parameter // Utile per scenari WSL2 o development remoto: ?wsHost=192.168.1.100:3001 const params = new URLSearchParams(location.search) - const wsHost = params.get('wsHost') || location.host + const defaultHost = ( + location.hostname === 'localhost' || location.hostname === '::1' + ) + ? `127.0.0.1${location.port ? `:${location.port}` : ''}` + : location.host + const wsHost = params.get('wsHost') || defaultHost const wsUrl = `${protocol}//${wsHost}/ws` console.log('[Controller] Connecting to WebSocket:', wsUrl) diff --git a/src/components/DisplayPage.vue b/src/components/DisplayPage.vue index 2a788b4..af90728 100644 --- a/src/components/DisplayPage.vue +++ b/src/components/DisplayPage.vue @@ -225,7 +225,12 @@ export default { // Permette di specificare un host WebSocket alternativo via query parameter // Utile per scenari WSL2 o development remoto: ?wsHost=192.168.1.100:5173 const params = new URLSearchParams(location.search) - const wsHost = params.get('wsHost') || location.host + const defaultHost = ( + location.hostname === 'localhost' || location.hostname === '::1' + ) + ? `127.0.0.1${location.port ? `:${location.port}` : ''}` + : location.host + const wsHost = params.get('wsHost') || defaultHost const wsUrl = `${protocol}//${wsHost}/ws` console.log('[Display] Connecting to WebSocket:', wsUrl) diff --git a/src/server-utils.js b/src/server-utils.js index 22ddecf..70b346a 100644 --- a/src/server-utils.js +++ b/src/server-utils.js @@ -32,8 +32,8 @@ export function printServerInfo(displayPort = 5173, controllerPort = 3001) { const networkIPs = getNetworkIPs() console.log(`\nSegnapunti Server`) - console.log(` Display: http://localhost:${displayPort}/`) - console.log(` Controller: http://localhost:${controllerPort}/`) + console.log(` Display: http://127.0.0.1:${displayPort}/`) + console.log(` Controller: http://127.0.0.1:${controllerPort}/`) if (networkIPs.length > 0) { console.log(`\n Controller da dispositivi remoti:`) diff --git a/vite-plugin-websocket.js b/vite-plugin-websocket.js index 6a60176..9ba79aa 100644 --- a/vite-plugin-websocket.js +++ b/vite-plugin-websocket.js @@ -4,6 +4,7 @@ import { setupWebSocketHandler } from './src/websocket-handler.js' import { printServerInfo } from './src/server-utils.js' const CONTROLLER_PORT = 3001 +const DEV_PROXY_HOST = process.env.DEV_PROXY_HOST || '127.0.0.1' /** * Plugin Vite che integra un server WebSocket per la gestione dello stato di gioco @@ -59,13 +60,13 @@ function startControllerDevServer(vitePort, wss) { // Proxy verso il dev server di Vite const proxyReq = httpRequest( { - hostname: 'localhost', + hostname: DEV_PROXY_HOST, port: vitePort, path: targetPath, method: req.method, headers: { ...req.headers, - host: `localhost:${vitePort}`, + host: `${DEV_PROXY_HOST}:${vitePort}`, }, }, (proxyRes) => { @@ -96,7 +97,7 @@ function startControllerDevServer(vitePort, wss) { } else { // Per l'HMR di Vite, proxare l'upgrade WebSocket verso Vite const proxyReq = httpRequest({ - hostname: 'localhost', + hostname: DEV_PROXY_HOST, port: vitePort, path: request.url, method: 'GET',