From cdb64f0ad832904378faf824a007163f6e07ad14 Mon Sep 17 00:00:00 2001 From: Nick Krecklow Date: Tue, 5 May 2020 17:52:28 -0500 Subject: [PATCH] auto assume WebSocket protocol using location.protocol --- README.md | 2 -- assets/js/socket.js | 7 ++++++- docs/CHANGELOG.md | 2 -- docs/MIGRATING.md | 13 ++++++------- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 394a1a2..ad1138a 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,6 @@ You can see an up-to-date copy of the production branch running on https://minet 5. Run ```npm run build``` (this bundles `assets/` into `dist/`) 6. Run ```node main.js``` to boot the system (may need sudo!) -If your deployment is using **https**, you will need to modify line 13 in `assets/js/socket.js` to use `wss://` instead of `ws://`. Otherwise browsers may prevent the WebSocket connection as it would be insecure on a secured connection. - (There's also ```install.sh``` and ```start.sh```, but they may not work for your OS.) Database logging is disabled by default. You can enable it in ```config.json``` by setting ```logToDatabase``` to true. diff --git a/assets/js/socket.js b/assets/js/socket.js index fd0d6de..256e9a0 100644 --- a/assets/js/socket.js +++ b/assets/js/socket.js @@ -10,7 +10,12 @@ export class SocketManager { } createWebSocket () { - this._webSocket = new WebSocket('ws://' + location.host) + let webSocketProtocol = 'ws:' + if (location.protocol === 'https:') { + webSocketProtocol = 'wss:' + } + + this._webSocket = new WebSocket(webSocketProtocol + '//' + location.host) // The backend will automatically push data once connected this._webSocket.onopen = () => { diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 63614b7..08be340 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -3,8 +3,6 @@ - Frontend reconnect behavior has been improved to use exponential backoff behavior (up to 30 seconds) with unlimited retries. - The "Lost connection!" message will now show the reconnection attempt timer. -If your deployment is using **https**, you will need to modify line 13 in `assets/js/socket.js` to use `wss://` instead of `ws://`. Otherwise browsers may prevent the WebSocket connection as it would be insecure on a secured connection. - **5.2.1** *(May 1 2020)* - The historical graph will now auto scale its yaxis steps. diff --git a/docs/MIGRATING.md b/docs/MIGRATING.md index f3a7592..f1741b0 100644 --- a/docs/MIGRATING.md +++ b/docs/MIGRATING.md @@ -8,13 +8,12 @@ Minetrack 5 is the first of several upcoming updates designed to address several 4. Open the directory and execute `npm install --build-from-source`. This will install updated (and new) dependencies needed by the program. 5. If you have `logToDatabase: true` in your `config.json`, make sure to copy your `database.sql` file into the new directory, otherwise you will lose historical server activity and records. 6. Copy your existing `config.json` and `servers.json` files into the new directory. -7. If your deployment is using **https**, you will need to modify line 13 in `assets/js/socket.js` to use `wss://` instead of `ws://`. Otherwise browsers may prevent the WebSocket connection as it would be insecure on a secured connection. -8. Build your copy of `dist/`. -9. If you have previously configured any `faviconOverride` values within `config.json`, you will need to move them to the updated structure. Create a new directory within your Minetrack folder named `favicons/`. -10. If you have previously configured any `minecraft.json` values not included in the new `minecraft_versions.json` file, you will need to update their structure copy them to the new file. -11. Move your custom favicon images into the directory. -12. Open `servers.json` in your favorite editor. -13. For any server which you have a custom favicon, set the "favicon" field like so: +7. Build your copy of `dist/`. +8. If you have previously configured any `faviconOverride` values within `config.json`, you will need to move them to the updated structure. Create a new directory within your Minetrack folder named `favicons/`. +9. If you have previously configured any `minecraft.json` values not included in the new `minecraft_versions.json` file, you will need to update their structure copy them to the new file. +10. Move your custom favicon images into the directory. +11. Open `servers.json` in your favorite editor. +12. For any server which you have a custom favicon, set the "favicon" field like so: ``` {