Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bypass is handling all requests regardless proxy options #829

Closed
koba04 opened this issue Mar 6, 2017 · 3 comments
Closed

bypass is handling all requests regardless proxy options #829

koba04 opened this issue Mar 6, 2017 · 3 comments

Comments

@koba04
Copy link
Contributor

koba04 commented Mar 6, 2017

webpack-dev-server is very helpful in my development. Thanks!

Currently, There is bypass in a proxy option. But bypass is applied all requests regardless of its a pass.

For instance, a server with the following webpack.config.js always returns api.json as a response (It depends on order of Object.keys).

const path = require('path');
const webpack = require('webpack');

module.exports = env => ({
  entry: './app.js',
  output: {
    filename: '[name].js',
    path: path.resolve(__dirname, 'public'),
  },
  devServer: {
    contentBase: path.join(__dirname, ''),
    proxy: {
      '/foo.html': {
        bypass() {
          return 'foo.txt';
        },
      },
      '/api/': {
        bypass() {
          return 'api.json';
        },
      },
   },
  },
});

I think the behavior is a little confusing.

Proposals

bypass is applied when a proxy has matched

To do that, we need to take a matching logic from http-proxy-middleware.

But I think it's the best way to solve this problem.

Move bypass option to outside proxy options

moving bypass options to outside proxy as proxyBypass is a clear way to tell developers proxyBypass is applied all requests regardless of proxy options.
But it seems to need to change webpack.config.js, which is painful for users.

Add a validation for multiple bypass options

This doesn't change the current behaviors. Users can notice it might not work well when they put multiple bypass options in proxy options

What do you think about this? I'd like to work on this.

Thanks.

@SpaceK33z
Copy link
Member

Your first proposal does make sense, but I'd prefer to not copy such a file in our repo. Of course we could also directly require that file, but that can be tricky.

Another way could perhaps be to make an issue/PR to http-proxy-middleware, to add such an option in there. Not sure if that makes sense, but could be interesting to see how he thinks about it.

@shellscape
Copy link
Contributor

Going to assert the suggestion to make this feature request with http-proxy-middleware so we can consume an option rather than implement it standalone in webpack-dev-server. We can revisit this issue should there need to be any work on this end.

@maks-humeniuk
Copy link

@shellscape, is this fixed or should I use pathRewrite: (path, request) => '/path/to/mock.json' instead for multiple paths?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants