webpack-dev-server icon indicating copy to clipboard operation
webpack-dev-server copied to clipboard

Webpack dev server proxy fails to proxy the chunk files for the first time

Open yudi704 opened this issue 7 years ago • 1 comments

  • Operating System: Windows 10
  • Node Version: 8.11.4
  • NPM Version: 5.6.0
  • webpack Version: 4.17.2
  • webpack-dev-server Version: 3.5.1
  • Browser: Chrome 75.0.3770.100
  • [ x] This is a bug
  • [ ] This is a modification request

Code

// webpack.config.js
devServer: {
    inline: true,
    port: 9000,
    index: "", // specify to enable root proxying
    historyApiFallback: true,
    publicPath: "http://localhost:9000/dist/",
    writeToDisk: true,
    disableHostCheck: true,
    hot: true,
    clientLogLevel: 'trace',
    proxy: [
      {
        context: () => true,
        target: "http://localhost/",
        logLevel: 'debug',
        pathRewrite: function(path, req) {
          var replacedPath = path;
          if (path.indexOf("MySite1") === -1) {
            replacedPath = replacedPath.replace("/", "/MySite1/" );
          }
          return replacedPath;
        },
        changeOrigin: true,
        bypass: function(req, res, proxyOptions) {
          if (req.path.indexOf("dist") !== -1) {
            return req.path;
          }
        }
      }
    ],
    headers: {
      "Access-Control-Allow-Origin": "*",
      "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
      "Access-Control-Allow-Headers":
        "X-Requested-With, content-type, Authorization"
    }
  },

Expected Behavior

With the above settings, all the request except the request with path /dist should be proxied.

Actual Behavior

When loading for the first time the /dist request for the "chunks" gets proxied to the localhost instead of serving it from localhost:9000? Proxy works intermittently upon refreshes after the first load.

For Bugs; How can we reproduce the behavior?

This is an angular project with feature project being loaded lazily. The lazy chunks also gets proxied when building and running the project first time and only works after several refreshes.

For Features; What is the motivation and/or use-case for the feature?

yudi704 avatar Jul 15 '19 05:07 yudi704

Invalid proxy configuration, sorry we can't help without fill reproducible test repo, feel free to feedback

alexander-akait avatar Jul 15 '19 10:07 alexander-akait