Skip to content

Websocket and /info requests go to wrong domain when using default port #2142

Closed
@jolyndenning

Description

@jolyndenning
  • Operating System: osx

  • Node Version: 12.6.0

  • NPM Version: 6.9.0

  • webpack Version: 4.36.1

  • webpack-dev-server Version: 3.7.2

  • Browser: Firefox and Chrome (both)

  • This is a bug

  • This is a modification request

Code

(See repo that demonstrates the problem: https://github.com/joeldenning/webpack-dev-server-ws-bug)

Run webpack-dev-server without a port specified (not through the CLI nor webpack config). The server will be automatically assigned a default port, usually 8080.

Now start a static http server on a different port (let's say port 5000). Create an html file that loads the webpack bundle: <script src="http://localhost:8080/main.js">.

Make sure that webpack-dev-server is configured to reload the page whenever the bundle is recompiled. The webpack-dev-server client will attempt to open a web socket to the wrong host. When the web socket fails, it will start making XHR requests to /info in an infinite loop, once every few seconds. Each of the requests will fail because they are to the wrong host.

Expected Behavior

The websocket and /info requests should go to http://localhost:8080. For example the XHR request for /info should go to http://localhost:8080/info.

Actual Behavior

The web socket and XHR requests go to http://localhost, without the :8080 port on it. For example, the /info request goes to http://localhost/info.

Note that if you specify --port 8080 when you run webpack-dev-server, that the behavior is corrected and the /info request goes to http://locahost:8080/info.

webpack-dev-server should work without having to specify a port.

For Bugs; How can we reproduce the behavior?

https://github.com/joeldenning/webpack-dev-server-ws-bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions