Skip to content

Share localhost / webpack-dev-server

Share webpack-dev-server at a public URL

webpack serve listens on localhost:8080, and whk share 8080 gives it an HTTPS link. The Invalid Host header page that tunnels are known for does not appear, because your dev server never sees the public hostname. Hot reload needs one client setting.

# terminal 1: the dev server
npx webpack serve

# terminal 2: the link
whk share 8080

The link is https://<name>.sharehooks.cc and works until you press Ctrl-C. No whk yet? Install it and log in, which takes a minute.

Start free:
or sign up with email

webpack-dev-server at a glance

Dev server
npx webpack serve, port 8080
Share it
whk share 8080
Setting to add
No host setting: allowedHosts is checked against Host, which arrives as localhost:8080. For hot reload, client.webSocketURL: "auto://0.0.0.0:0/ws".
Without it
The page and bundles load. Without the socket setting, the hot reload client tries port 8080 on the public name and never connects.
Hot reload
Yes, once client.webSocketURL lets the client use the page's own host and port.
URLs and cookies
Nothing to set: the dev server serves files and builds no absolute URLs. A backend you reach through devServer.proxy sees the dev server as its client.

Your dev server gets each request with Host: localhost:8080; the public name travels in X-Forwarded-Host, with X-Forwarded-Proto: https. What your server sees has the rest.

Why there is no Invalid Host header

webpack-dev-server answers only hosts it expects. With the default allowedHosts: "auto" those are localhost, names under .localhost, IP addresses and the configured host. Anything else gets status 403 and the body Invalid Host header, which is what a tunnel produces when it passes its public hostname through.

whk share sends Host: localhost:8080, so the default passes and allowedHosts can stay as it is. The setting, for tunnels that do need it, takes a leading dot for subdomains:

webpack.config.js

module.exports = {
  devServer: {
    // Not needed for whk share; for tunnels that send the public Host
    allowedHosts: [".sharehooks.cc"],
  },
};

Avoid allowedHosts: "all". The webpack docs say it in capitals: a server that does not check the host is open to DNS rebinding attacks.

Point the hot reload client at the page's own address

The dev server's socket lives at /ws on the same port, and the server checks both Host and Origin on it; a mismatch closes the socket with Invalid Host/Origin header. The link sends a WebSocket's Origin as your local origin, so the server side accepts it.

The client side is the catch. The bundle is told which port to dial, and that is the dev server's port: a page opened at https://<name>.sharehooks.cc tries wss://<name>.sharehooks.cc:8080/ws, a port the link does not have. Tell the client to take protocol, hostname and port from the browser instead:

webpack.config.js

module.exports = {
  devServer: {
    client: {
      // Use the page's own protocol, host and port for the socket
      webSocketURL: "auto://0.0.0.0:0/ws",
    },
  },
};

With that, the same config works on localhost:8080 and through the link: the socket goes to whatever address the page came from.

Cross-origin requests and proxied APIs

The dev server also refuses script-tag style requests from other sites (403 with Cross-Origin request blocked) and sets Cross-Origin-Resource-Policy: same-origin on what it serves. A visitor's page and its bundles are the same origin on the link, so neither gets in the way.

If your app calls a backend on another port, put it behind devServer.proxy so it shares the dev server's origin. A share is one port, and the visitor's browser cannot reach a second one on your machine.

webpack-dev-server questions

Sources

The webpack-dev-server settings and messages on this page are from the official documentation and source for webpack-dev-server 6.1, read on 12 November 2026. What the link does to a request is from the whk share docs.

Other frameworks

All 14 framework guides

Send someone your webpack-dev-server app

Sign up free, install the CLI and run whk share 8080.

or sign up with email

No credit card