fix(dev): evita problemi IPv6 di localhost su ws e proxy controller
Usa fallback a 127.0.0.1 quando l'hostname è localhost/::1 nei client websocket display/controller. Instrada il proxy del controller dev verso Vite tramite DEV_PROXY_HOST (default 127.0.0.1). Mostra gli URL locali del server con 127.0.0.1 per una diagnostica coerente su Raspberry/Linux.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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:`)
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user