drewzboto / grunt-connect-proxy

Grunt Connect support for proxying API calls during development
MIT License
423 stars 122 forks source link

Add function support to context rewrites #109

Closed cinaglia closed 9 years ago

cinaglia commented 9 years ago

Hi there,

This PR adds support for (possibly?) smarter context rewrites. It allows use of functions when performing String.prototype.replace() calls (see reference). A use case to explain why I've needed this recently:

{
  host: 'www.example.com',
  context: '/books',
  rewrite: {
    'page=(\\d+)': function(match, p1) {
      var per_page = 10;
      return '_offset=' + (per_page * p1);
    }
  }
}

This allowed me to easily transform /books?page=1 into /books?_offset=10.

cinaglia commented 9 years ago

Thanks for the merge! :+1:

drewzboto commented 9 years ago

Thanks for the PR!