Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add by location reverse-proxying #5

Closed
dready92 opened this issue Jul 29, 2010 · 4 comments
Closed

Add by location reverse-proxying #5

dready92 opened this issue Jul 29, 2010 · 4 comments

Comments

@dready92
Copy link

http://server.com/foo reversed to http://internal-server1/foo
http://server.com/bar reversed to http://internal-server2/bar

@Marak
Copy link
Contributor

Marak commented Jul 29, 2010

Hello! I'm a little confused about this.

The current implementation should pass the original request object which will contain a "url" property.

Can you explain how this implementation doesn't achieve the functionality you want? Are you talking about parking a router in-front of the reverse proxy so you can dynamically route requests?

Could you possibly write a test case or perhaps pseudo code what the api for this would look like?

Thanks!

@dready92
Copy link
Author

You're right, certainly it wasn't a good day yesterday ! Anyway I was thinking to a sort of a thin "router" layer on top of that to automate a little bit the process.

As an example : if you want to reverse proxy http://www.server.com/foo to http://server1.local/foo , instead of having to :

  • modify the URL property of the request
  • check for the response headers of server1.local and rewrite the "Redirect" header if any
  • and perhaps some other things I don't think of now

just have something to predefine route, a bit of code to illustrate :

var httpProxy = require('http-proxy').httpProxy;
httpProxy.setRoute( "/foo", { 
    "destination": "http://server1.local/foo"
});
http.createServer(function (req, res){
    var proxy = new httpProxy;
    if ( proxy.route(req,res) ) {
        // proxy handled the request because one of the pre-set routes match
        return ;
    }
    // no route were defined by setRoute
    }
}).listen(8000);

That way you provide features for common reverse-proxying needs, ex cookie rewriting, load-balancing, encoding ...

@Marak
Copy link
Contributor

Marak commented Jul 30, 2010

Okay, that makes a lot of sense.

The codebase we extracted this from does have a router and (somewhat of a) load balancer. I didn't want to clutter http-proxy api, but you do have a valid point. While having the raw access to httpProxy.proxyRequest() is great, most people will want the more advanced functionality you mentioned.

I could write a new router for this, or use a pre-existing one. I'm going to think on this for a few days and determine the best plan of attack. It's important to me that we keep the api clean, but I think there is a good solution to be had here. Hopefully I'll have a patch by next week.

In the meantime, do you think you could elaborate on the functionality you mentioned of cookie rewriting and encoding?

Thanks a lot for your feedback, it's much appreciated.

@indexzero
Copy link
Contributor

Fixed in 0.3.1:

npm install http-proxy@0.3.1

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants