odojs / redwire

A dynamic, high performance, load balancing reverse proxy
MIT License
34 stars 3 forks source link

Post Proxy Middleware / Response Modification Support #11

Open wei opened 8 years ago

wei commented 8 years ago

Hi there,

Is there any support for post proxy middleware or response modification? I'm looking to replace urls in the response html and js files.

Thanks! ddhhz

TwistaTim commented 8 years ago

Hi ddhhz, You can manipulate urls by adding another function using the use directive. ie:

var RedWire = require('redwire');
var redwire = new RedWire({
    http: { port: 80 }
});

redwire.http('example.com', '127.0.0.1:3000');

manipulate = function(mount, url, req, res, next) {
    if (req.url.indexOf('/testplace/') === 0) {
      req.url += 'add this';
      url += 'add this';
    }
    return redwire.proxy()(mount, url, req, res, next);
  };

redwire.http('example.com/api').use(manipulate);

Hope this helps.

Cheers