1

I can't get the websocket to work when the app is on HTTPS and the dev server is on HTTP.

I'm running webpack-dev-server on the default http://localhost:8080. My app runs on https://myapp.test and references http://localhost:8080/js/app.js. This works but when it tries to create the websocket connection it requests it on https://192.168.178.20:8080/... and that fails:

failed requests screenshot

192.168.178.20 is my local IP address so when I manually change the https to http it loads correctly. And if I serve the exact same app over HTTP on http://myapp.test it's all hunkydory:

enter image description here

Alternatively if I set devServer: { https: true } in the webpack config that also works but only after I manually accept the self signed certificate.

Isn't there a way to load the socket on an HTTP connection from an HTTPS page?

Tamlyn
  • 22,122
  • 12
  • 111
  • 127

1 Answers1

1

Forcing HTTPS is deliberate but there's an exception if hostname===127.0.0.1:

devServer: {
  host: '127.0.0.1'
}

See the source code.

Tamlyn
  • 22,122
  • 12
  • 111
  • 127