brunch / auto-reload-brunch

Adds automatic browser reloading support to brunch.
88 stars 30 forks source link

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

Closed clarknelson closed 4 years ago

clarknelson commented 5 years ago

Offending line: https://github.com/brunch/auto-reload-brunch/blob/b8678226d177c715de0056bb244afb2779e36cb2/vendor/auto-reload.js#L69

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 commented 5 years ago

image

clarknelson commented 5 years ago

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 commented 4 years ago

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

harryfinn commented 4 years ago

@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 https://github.com/brunch/auto-reload-brunch/blob/ae882c57cbef880afbf47cd7d66120320e13f8c6/index.js#L138 - 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