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

Support filter option for full control over path matching #469

Merged
merged 1 commit into from
Feb 3, 2017

Conversation

atesgoral
Copy link
Contributor

https://github.com/chimurai/http-proxy-middleware#http-proxy-middleware-options

custom matching

For full control you can provide a custom function to determine which requests should be proxied or not.

/**
 * @return {Boolean}
 */
var filter = function (pathname, req) {
    return (pathname.match('^/api') && req.method === 'GET');
};

var apiProxy = proxy(filter, {target: 'http://www.example.org'})

With this small change, it is possible to pass a filter property in a proxy table entry to use a request filter function instead of using the proxy table key as the context. The context is ignored. For example:

proxyTable: {
  '/': { // The root page is rendered the backend
    target: 'http://localhost:6543',
    filter: (pathname, req) => {
      return pathname === '/'; // Only proxy the root path, bypass for other build artifacts
    }
  },
  '/api': {
    target: 'http://localhost:6543'
  },
  ...

@yyx990803 yyx990803 merged commit 1ecd9a7 into vuejs-templates:master Feb 3, 2017
@atesgoral atesgoral deleted the filter-support branch February 3, 2017 23:48
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

Successfully merging this pull request may close these issues.

2 participants