webpack-dev-server: proxy.bypass return false does not work

  • Operating System: MacOS High Sierra
  • Node Version: 11.0.0
  • NPM Version: 6.4.1
  • webpack Version: 4.29.5
  • webpack-dev-server Version: 3.2.0
  • This is a bug
  • This is a modification request

Code

does not work:

// webpack.config.js

module.exports = {
  devServer: {
    proxy: {
      '**': {
        bypass(req) {
          if (!req.headers.accept.includes('application/json'))
            return false; // ← does nothing
        },
        target: `http://localhost:${yargs.proxyPort}`,
      },
    },
  },
  entry: './app',
}

does work:

// webpack.config.js

module.exports = {
  devServer: {
    proxy: {
      '**': {
        bypass(req) {
          if (!req.headers.accept.includes('application/json'))
            return req.url;
        },
        target: `http://localhost:${yargs.proxyPort}`,
      },
    },
  },
  entry: './app',
}

Expected Behaviour

Based on the vague explanation in the docs

It must return either false or a path that will be served instead of continuing to proxy the request.

I expect return false to skip the proxy

Actual Behaviour

return false does nothing.

For Bugs; How can we reproduce the behaviour?

Minimal example: https://github.com/jsmith-sapient/local-api-mocker

npm run start:dev

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

@jsmith-sapient i will look on this in near future, anyway we glad any help