Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

ws: causes an error on HTTPS websites. Should be wss: #86

Closed
clarknelson opened this issue Feb 6, 2019 · 4 comments
Closed

ws: causes an error on HTTPS websites. Should be wss: #86

clarknelson opened this issue Feb 6, 2019 · 4 comments

Comments

@clarknelson
Copy link
Contributor

Offending line:

var connection = new WebSocket('ws://' + host + ':' + port);

Error Message:
auto-reload.js:69 Mixed Content: The page at 'https://........./' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://..........:9485/'. This request has been blocked; this endpoint must be available over WSS.

Solution:
if(window.location.protocol === 'https:'){ var connection = new WebSocket('wss://' + host + ':' + port); } else if (window.location.protocol == 'http:'){ var connection = new WebSocket('wss://' + host + ':' + port); }

@clarknelson
Copy link
Contributor Author

image

@clarknelson
Copy link
Contributor Author

I have implemented the code above, now instead of getting "this endpoint must be available over WSS" I am getting time outs. I have modified the config to point to my key/cert files on the server.

@clarknelson
Copy link
Contributor Author

I ended up resolving my issue by disabling auto reload in my live environment.

@harryfinn
Copy link

@clarknelson I came across the same issue this evening - turns out the documentation on the master branch is not correct for the latest tagged release (v2.7.1), which states that there is a param called forcewss that can be used in the plugin config section of your brunch-config.js (or similar). This parameter is only available in the master branch, so I ran into the same issue using version 2.7.1 which is what get installed via package manager

If you look at line 138 for v2.7.1

if (this.enabled && this.ssl) {
- it performs a check against this.ssl which is set based on whether you have specificed the keyPath & certPath options in your brunch config. If you set those paths to your valid ssl cert then auto-reload correctly switches ws to wss and corrects the https errors

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants