Make WebSocket connection protocol dependent (#191)

Currently, the connection to WebSockets is hardcoded to the protocol "ws://".

If the server is put behind a proxy server (like Nginx) to support "https", the connection to websockets will fail (at least in Firefox) due to insecure protocol.

This change checks the current protocol and connects to "wss" if loaded via "https", which makes it work when loaded via proxy.
This commit is contained in:
Pablo Gonzalez
2024-01-04 19:18:14 +01:00
committed by GitHub
parent 022f72eee7
commit 9da9ac9395
2 changed files with 2 additions and 1 deletions

Binary file not shown.

View File

@@ -113,7 +113,8 @@ function loadTags(pos) {
}
function connect() {
socket = new WebSocket("ws://" + location.host + "/ws");
protocol = location.protocol == "https:" ? "wss://" : "ws://";
socket = new WebSocket(protocol + location.host + "/ws");
socket.addEventListener("open", (event) => {
showMessage("websocket connected");