I'm still new still newish to node, and having some troubling figuring out how to set a new response body with the http-proxy-middleware
package.
That is, I have the following small program that proxies requests
var express = require('express');
var proxy = require('http-proxy-middleware');
var app = express();
app.use('**', proxy({
target: 'http://alanstorm.com',
changeOrigin: true,
onProxyRes:function (proxyRes, req, res) {
//I want to do something here to change the response
console.log("Called");
console.log(proxyRes);
console.log(res);
}
}));
app.listen(3000);
i.e. -- I can make a request to http://localhost:3000
, and it will proxy the request to my personal website.
I've also successfully setup a response listener (onProxyRes
) above. I seem to have access to a proxy response object, a request object, and a response object. What I'd like to do is, in the onProxyRes
method, is change the response if certain things are true or not.
However, it's not clear how to do this with the proxyRes
or res
objects, and I'm not sure how to look up the available methods on these objects. I tried console.log
ing them for useful properties, and found nothing useful.
If someone know how i can modify the bodies of the response objects, that would be great. If someone can tell me how I can figure out what methods exist on those objects, that would be extra great.