Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get webpack-dev-server to ignore all but a certain path in the proxy settings?

I've got my WDS running on port 9000, and the webpack bundles located under /dist/ I've got a back end server running on port 55555

Is there a way to get WDS to ignore (proxy to 55555) every call except those starting with /dist/?

I've got the following:

  devServer: {
    port: 9000,
    proxy: {
      "/dist": "http://localhost:9000",
      "/": "http://localhost:55555"
    }
  }

Trouble is, that root ("/") just overrides everything...

Thanks for any advice you can offer.

UPDATE: I've gotten a little farther with the following:

proxy: {
    "/": {
        target: "http://localhost:55555",
        bypass: function(req, res, proxyOptions) {
            return (req.url.indexOf("/dist/") !== -1);
        }
    }
},

But the bypass just seems to kill the connection. I was hoping it would tell the (9000) server to not proxy when the condition is true. Anybody know a good source explaining "bypass"?

like image 485
Eric Avatar asked Nov 21 '25 17:11

Eric


1 Answers

Webpack allows glob syntax for these patterns. As a result, you should be able to use an exclusion to match "all-but-dist".

Something like this may work (sorry I don't have webpack in front of me at the moment):

devServer: {
  port: 9000,
  proxy: {
    "!/dist/**/*": "http://localhost:55555"
  }
}
like image 178
Mr. S Avatar answered Nov 24 '25 11:11

Mr. S



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!