hoxy
hoxy copied to clipboard
reverse proxy for multiple domain?
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!
How would it know which domain to forward to?
could we use hostname from request to forward?
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';
}
});
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.
Agreed that it's best implemented as a separate module.