waterlink / rack-reverse-proxy

A Reverse Proxy for Rack
MIT License
196 stars 52 forks source link

Matching on the host and path? #29

Closed bugthing closed 10 months ago

bugthing commented 8 years ago

First off, thanks very much this gem, I find it most useful

I would love to do something like this:

reverse_proxy /^http://(.+?).example.com/foo$/, 'http://$1.otherplace.com/'

As you can see it involves matching on the whole URL.

Is there anyway to do this currently?

vemv commented 7 years ago

I'd like to second this question - can one match by hostname?

This could be a generic 'constraints' mechanism, just like in Rails:

constraints(-> (req) { req.host == 'foo.com' }) do ...

The good thing with this approach is that the programmer can access the whole rack request object (req), therefore being able to do all kind of matchings.

waterlink commented 7 years ago

I think there is a pattern evolving from these requirements. How about providing a block that accepts whole request object and is capable to construct proxied URL on its own? vemv notifications@github.com schrieb am So., 9. Okt. 2016 um 9:48 AM:

I'd like to second this question - I one match by hostname?

This could be a generic 'constraints' mechanism, just like in Rails:

constraints(-> (req) { req.host == 'foo.com' }) do ...

The good thing with this approach is that the programmer can access the whole rack request object (req), therefore being able to do all kind of matchings.

— You are receiving this because you are subscribed to this thread.

Reply to this email directly, view it on GitHub https://github.com/waterlink/rack-reverse-proxy/issues/29#issuecomment-252470993, or mute the thread https://github.com/notifications/unsubscribe-auth/AAlLFu86tjVmhjNE5XEmIHFrWL2h1aYQks5qyJxPgaJpZM4IDAIK .

vemv commented 7 years ago

Hey! Thanks for the answer.

We might have different things in mind. What the constraints blocks do in Rails routes is to determine whether to apply the thing or not.

So what -> (req) { req.host == 'foo.com' }) does in my example is to return a boolean, which would mean 'yes, do proxy this specific request'.

Constructing 'proxied urls' sounds more complicated than that.

@bugthing's requirements would be satisfiable with my approach. You can inspect protocol, host, etc from an env object.