mirror of
https://github.com/Roslund/meshtastic-map.git
synced 2026-03-28 17:43:03 +01:00
Refactor WebSocket connection logic to differentiate between localhost and production environments
This commit is contained in:
@@ -4340,9 +4340,11 @@
|
|||||||
function connectWebSocket() {
|
function connectWebSocket() {
|
||||||
// Determine WebSocket URL - use same hostname as current page, port 8081
|
// Determine WebSocket URL - use same hostname as current page, port 8081
|
||||||
const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||||
const wsHost = window.location.hostname;
|
// Heuristic: if running on localhost, use port 8081; otherwise use /ws path via Nginx
|
||||||
const wsPort = '8081';
|
const isLocalhost = location.hostname === 'localhost' || location.hostname === '127.0.0.1';
|
||||||
const wsUrl = `${wsProtocol}//${wsHost}:${wsPort}`;
|
const wsUrl = isLocalhost
|
||||||
|
? `${wsProtocol}//${location.hostname}:8081`
|
||||||
|
: `${wsProtocol}//${location.host}/ws`;
|
||||||
|
|
||||||
console.log('Connecting to WebSocket:', wsUrl);
|
console.log('Connecting to WebSocket:', wsUrl);
|
||||||
ws = new WebSocket(wsUrl);
|
ws = new WebSocket(wsUrl);
|
||||||
|
|||||||
Reference in New Issue
Block a user