0

Http-Proxy, like adapter, adds "/store-name" at the last of the proxy target that I specify.
I want to have complete control of the URL ,or atleast I should be able to add suffix to the url.

The file server/proxies/members.js looks like this for me.

var proxyPath = '/members';

module.exports = function(app) {
// For options, see:
// https://github.com/nodejitsu/node-http-proxy
var proxy = require('http-proxy').createProxyServer({});

proxy.on('error', function(err, req) {
console.error(err, req.url);
});

app.use(proxyPath, function(req, res, next){
// include root path in proxied request
req.url = proxyPath + '/' + req.url;
proxy.web(req, res, { target: 'http://localhost:8082/connection/testdb?tablename=' });
});
};

As the final url is this case looks like

"http://localhost:8082/connection/testdb?tablename=/members/"

instead i want

http://localhost:8082/connection/testdb?tablename=storename

P.S.: Is something like "buildURL=url" , possible in http-proxy

sidharth
  • 3
  • 6

1 Answers1

0

I'm unclear on exactly what you're trying to do, but take a look at the prependPath and ignorePath options to proxy.createProxysServer() (https://github.com/nodejitsu/node-http-proxy#options)

Update: Setup a proxyReq handler on the proxy object and you can manipulate the path any way you want. For example:

proxy.on('proxyReq', function(proxyReq, req, res, options) {
    proxyReq.path = '/custom/path/here';
});
keithmo
  • 4,893
  • 1
  • 21
  • 17
  • when we create a proxy url `http://localhost:8080` , and hit it with `Em.store.findAll('member')` , now if you check the url the passed url is `http://localhost:8080/members/`.Hence `"/members/"` seems to get added by default what i am asking is ,how can i change this url to something else ex: `http://localhost:8080/member?tablename=table`,i.e. add suffix or even remove the forced addition of `"/members/"`. ? – sidharth Sep 21 '15 at 08:42