reverse-proxy icon indicating copy to clipboard operation
reverse-proxy copied to clipboard

How to use regular expression in Cluster Address ?

Open dantemayson opened this issue 2 years ago • 8 comments

Hello. I have several addresses, some of which are variable

https://localhost:5000/viewer/10.2.410.2010029.100002.2022084318?wadouri=abdc
https://localhost:5001/viewer/1.2.410.20029.00002.20220207084318?wadouri=ef
https://localhost:5002/viewer/17.2.410.200029.002.2022020718?wadouri=fav

10.2.410.2010029.100002.2022084318 1.2.410.20029.00002.20220207084318 17.2.410.200029.002.2022020718

How can I use regex instead of these strings? example :

"Clusters": {
      "cluster1": {
        "Destinations": {
          "destination1": {
            "Address": "https://localhost:5000/viewer/regex(?)?wadouri=abdc"
          } 
        }
      },

dantemayson avatar Jan 09 '24 11:01 dantemayson

What sort of modifications did you want to make to the destination address?

If all you are changing is the host and keeping the path the same, you can set the Address to https://localhost:5000/, as that indicates the prefix used, not the final URL. E.g. with a request to https://localhost:5002/viewer/123.456.789?wadouri=fav and "Address": "https://localhost:5000/", the request to the backend would be https://localhost:5000/viewer/123.456.789?wadouri=fav.

If you wanted to make modifications (e.g. move which segment the unique value is in), you can look at https://microsoft.github.io/reverse-proxy/articles/transforms.html

MihaZupan avatar Jan 09 '24 17:01 MihaZupan

The problem is in addressing, not transform

dantemayson avatar Jan 15 '24 20:01 dantemayson

Can you share a few examples of how you're hoping to proxy requests? It's not clear to me from your description.

E.g.

https://proxy/foo => https://backend/foo
...

MihaZupan avatar Jan 18 '24 15:01 MihaZupan

Can you share a few examples of how you're hoping to proxy requests? It's not clear to me from your description.

E.g.

https://proxy/foo => https://backend/foo
...

I have a service that can open the corresponding file based on a specific value. This service is located on different servers. I want to put these services behind yarp regardless of the specific value.


specific value example : 10.2.410.2010029.100002.20220843218
specific value example : 102.2.410.201043029.100002.20222084318
specific value example : 10.2.410.2010029.1030002.202203384318
specific value example : 10.2.410.201230029.10220002.20220384318
which changes for each request

"Clusters": {
      "cluster1": {
        "Destinations": {
          "destination1": {
            "Address": "https://localhost:5000/viewer/{specific value}?wadouri=abdc"
          } 
        }
      },
"Clusters": {
      "cluster2": {
        "Destinations": {
          "destination1": {
            "Address": "https://localhost:5001/viewer/{specific value}?wadouri=abdc"
          } 
        }
      },
"Clusters": {
      "cluster3": {
        "Destinations": {
          "destination1": {
            "Address": "https://localhost:5002/viewer/{specific value}?wadouri=abdc"
          } 
        }
      },

I want to use regex instead of these values

dantemayson avatar Jan 19 '24 18:01 dantemayson

Can you include the routes as well? E.g. How do you decide which request goes to which cluster?

Tratcher avatar Jan 19 '24 21:01 Tratcher

Can you include the routes as well? E.g. How do you decide which request goes to which cluster?

"ReverseProxy": {
    "Routes": {
      "route1": {
        "ClusterId": "cluster1",
        "CorsPolicy": "customPolicy",
        "Match": {
          "Path": "/s1/{**catch-all}"
        },
        "Transforms": [
          { "PathPattern": "{**catch-all}" }
        ]
      },
      "route2": {
        "ClusterId": "cluster2",
        "CorsPolicy": "customPolicy",
        "Match": {
          "Path": "/s2/{**catch-all}"
        },
        "Transforms": [
          { "PathPattern": "{**catch-all}" }
        ]
      },
      "route3": {
        "ClusterId": "cluster3",
        "CorsPolicy": "customPolicy",
        "Match": {
          "Path": "/s3/{**catch-all}"
        },
        "Transforms": [
          { "PathPattern": "{**catch-all}" }
        ]
      },

dantemayson avatar Jan 20 '24 07:01 dantemayson

Url manipulation should be done by route transforms, not destination. Try this:

"ReverseProxy": {
    "Routes": {
      "route1": {
        "ClusterId": "cluster1",
        "CorsPolicy": "customPolicy",
        "Match": {
          "Path": "/s1/{**catch-all}"
        },
        "Transforms": [
          { "PathPattern": "/viewer/{**catch-all}" },
          { "QueryValueParameter": "wadouri", "Append": "abdc" }
        ]
      },
      "route2": {
        "ClusterId": "cluster2",
        "CorsPolicy": "customPolicy",
        "Match": {
          "Path": "/s2/{**catch-all}"
        },
        "Transforms": [
          { "PathPattern": "/viewer/{**catch-all}" },
          { "QueryValueParameter": "wadouri", "Append": "abdc" }
        ]
      },
      "route3": {
        "ClusterId": "cluster3",
        "CorsPolicy": "customPolicy",
        "Match": {
          "Path": "/s3/{**catch-all}"
        },
        "Transforms": [
          { "PathPattern": "/viewer/{**catch-all}" },
          { "QueryValueParameter": "wadouri", "Append": "abdc" }
        ]
      },
"Clusters": {
      "cluster1": {
        "Destinations": {
          "destination1": {
            "Address": "https://localhost:5000/"
          } 
        }
      },
      "cluster2": {
        "Destinations": {
          "destination1": {
            "Address": "https://localhost:5001/"
          } 
        }
      },
      "cluster3": {
        "Destinations": {
          "destination1": {
            "Address": "https://localhost:5002/"
          } 
        }
      },

Tratcher avatar Jan 22 '24 17:01 Tratcher

Triage: Looks to answered above, closing. Feel free to reopen if we got it wrong.

karelz avatar Jan 30 '24 18:01 karelz