hoxy icon indicating copy to clipboard operation
hoxy copied to clipboard

reverse proxy for multiple domain?

Open devchuanlink opened this issue 10 years ago • 5 comments
trafficstars

Hello! This is very useful tool for testing. for my case, I want it not only intercept one domain in reverse proxy mode but only multiple domain. Hope you consider it. thanks!

devchuanlink avatar Jul 23 '15 07:07 devchuanlink

How would it know which domain to forward to?

greim avatar Jul 23 '15 15:07 greim

could we use hostname from request to forward?

devchuanlink avatar Jul 24 '15 02:07 devchuanlink

I'm still not sure I follow. In reverse proxy mode, there's only one possible request hostname in the first place: the one declared in the reverse option.

You could switch it based on some other thing, such as the URL. But you could just do that with an intercept:

var proxy = new hoxy.Proxy({
  // most requests go to foo.com
  reverse: "http://foo.com"
});
proxy.intercept('request', function(req) {
  if (/somepattern/.test(req.url)) {
    // but some requests go to bar.com
    req.hostname = 'bar.com';
  }
});

greim avatar Jul 24 '15 02:07 greim

I have been working on this at my company for a long time. It isn't easy, because it tends to break assumptions made by the target website, which you then have to correct for.

For example, when relying upon the path (what hoxy calls the "url") of the request, as shown above, root/host relative URLs in the target page like this ...

/mypage.html

... no longer work properly. You can try to re-write these, but plenty of URLs are computed by JavaScript on the client.

That said, it would be awesome to see hoxy support an abstracted routing mechanism to achieve multi-domain reverse proxying at a basic level. I currently do: reverse: 'http://proxyisbroken.com' but then ignore that value and implement my own logic for routing.

But going much beyond that and doing this The Right Way™ probably belongs in a separate project. And I plan to (at some point) release a module that sits on top of hoxy that will do all the magic URL re-writing and such.

sholladay avatar Aug 11 '15 18:08 sholladay

Agreed that it's best implemented as a separate module.

greim avatar Aug 11 '15 20:08 greim