Description
-
Operating System: macOS 10.14.5
-
Node Version: 12.4.0
-
NPM Version: 6.9.0
-
webpack Version: 4.38.0
-
webpack-dev-server Version: 3.7.2
-
Browser: Google Chrome 75.0.3770.100
-
This is a bug
-
This is a modification request
Code
Repository with repro: https://github.com/maxlk/webpack-hmr-behind-proxy-issue/
// webpack.config.js
//...
devServer: {
hot: true,
public: "localhost:8080",
sockHost: "localhost",
sockPort: 8080,
disableHostCheck: true
}
//...
A website is served by 3rd party HTTP server. For example it's served from origin http://local.myhost.com
.
JavaScript bundle is served by WDS and is loaded loaded from different origin, for example http://localhost:8080
.
Expected Behavior
HMR should load updates from WDS URL. It is provided in public
and publicPath
config options. It's also available in sockHost
, sockPort
and sockPath
config options.
Update's URL should be like http://localhost:8080/5cc71fea9aecb707e3fc.hot-update.json
.
Actual Behavior
HMR tries to load update from window.location
(even with pathname
(?!)) instead of building the correct URL from config (<public><publicPath><update-hash>.hot-update.json
or <sockHost>:<sockPort>/<sockPath>/<update-hash>.hot-update.json
).
Particularly in this example it tries to load update from http://local.myhost.com/some/path/5cc71fea9aecb707e3fc.hot-update.json
.
It causes 404 error, hot reload fails and full reload is triggered.
For Bugs; How can we reproduce the behavior?
git clone [email protected]:maxlk/webpack-hmr-behind-proxy-issue.git
cd webpack-hmr-behind-proxy-issue
npm install
npm start
- Open
http://localhost:9876/www/
in web browser. - Open DevTools and make sure that Preserve log is enabled in Console and Network.
- Make any change in
src/print.js
and save it. - You will get
GET http://localhost:9876/www/5cc71fea9aecb707e3fc.hot-update.json 404 (Not Found)
error and full reload (instead of hot reload) will be triggered.