Macil / browserify-hmr

Hot Module Replacement plugin for Browserify
MIT License
373 stars 26 forks source link

Make the default updateUrl compatible with HTTPS #36

Open billiegoose opened 7 years ago

billiegoose commented 7 years ago

The default updateUrl (http://localhost:3123) is blocked by Chrome when testing my site using HTTPS and using the -K key.pem -C cert.pem options.

image

The websocket connection does work if I specify -u https://localhost:3123 explicitly. However, I don't think I'm unique in preferring the default settings to work out-of-the-box! So I fixed this the simplest way I could: by making the default updateUrl //localhost:3123 instead of http://localhost:3123. This tells the browser to use whichever protocol (HTTP or HTTPS) was used to load the webpage itself.

I updated the README and can say it works on my machine. (I was unable to run the tests on Windows.)

Macil commented 7 years ago

This would break using browserify-hmr on file:// URIs by default.

preferring the default settings to work out-of-the-box!

HTTPS isn't part of the default settings though.

I agree it's too bad that specifying the key and cert options isn't enough to get it to just work, but there's multiple factors in the url in websocket mode (protocol, address, and port number) and it gets pretty confusing if each part is separately auto-determined based on other options and the whole thing is also overridable. (Previous versions of browserify-hmr did this before I finally changed it because it tended to confuse even me.) Currently my position is that if the user is tweaking some of the settings already, then the url setting is also the user's responsibility. Maybe the documentation is lacking around this.

billiegoose commented 7 years ago

Ah.... good points. I don't know if the documentation is lacking though, since I did solve my issue fairly quickly. Maybe an example using HTTPS could be added to the ## Plugin Usage section?