I'm using the RoutingProxy class (found in the http-proxy package) to proxy certain requests in my node app. I'm having difficulty, however, in adding a prefix to the target path. For example, I'm trying to proxy http://localhost:8080/stylesheets/main.css to http://172.30.6.11:51161/mysite/stylesheets/main.css.
Here's a dumb example of what I'm trying to do:
// controllers/proxy.js
var httpProxy = require('http-proxy');
exports.request = function(options){
var proxy = new httpProxy.RoutingProxy();
return function(req, res){
req.url = '/mysite' + req.url;
proxy.proxyRequest(req, res, options);
};
};
// app.js
// ...
var controllers = require('./controllers');
app.use(controllers.proxy.request({
target: {
host: '172.30.6.11',
port: 55161
}
});
// ...
Unfortunately the prefix is never added when calling the target. Does anyone have any idea on how I can make this happen?
Normally we don't use http-proxy with express, but with http.createServer. But here is a workaround in the below comments of this issue