Refactor WebSocket connection logic to differentiate between localhost and production environments
This commit is contained in:
parent
aadd038880
commit
f7fbb38961
1 changed files with 5 additions and 3 deletions
|
|
@ -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);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue