1

I have 2 web (not api, let's assume razor) applications. I'm trying to put them behind Yarp reverse proxy.

Here's my config:

 "Yarp": {
"Routes": {
  "web-route1": {
    "ClusterId": "web-cluster1",
    "Match": {
      "Path": "/web1/{**catch-all}"
    },
    "Transforms": [
      { "PathPrefix": "/web1" }
    ]
  },
  "web-route2": {
    "ClusterId": "web-cluster2",
    "Match": {
      "Path": "/web2/{**catch-all}"
    },
    "Transforms": [
      { "PathPrefix": "/web2" }
    ]
  }
},
"Clusters": {
  "web-cluster1": {
    "Destinations": {
      "destination1": {
        "Address": "http://localhost:5135/"
      }
    }
  },
  "web-cluster2": {
    "Destinations": {
      "destination1": {
        "Address": "http://localhost:5022/"
      }
    }
  }

}

Let's say Yarp app sits at http://localhost:5000. The goal is to have apps respond at http: http://localhost:5000/web1 and http://localhost:5000/web2 correspondingly.

Needless to say it doesn't work. Anyone had successful experience?

I tried PathRemovePrefix which works for a single app but it obviously removes the crucial prefix.

2 Answers2

0

Change this

"Transforms": [
  { "PathPrefix": "/web2" }
]

TO

"Transforms": [
  { "PathPrefix": "{**catch-all}" }
]
prathap m
  • 1
  • 1
  • This way neither app responds – basilklochko Dec 14 '22 at 00:04
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 15 '22 at 14:47
0

You need to change the { "PathPrefix": "/web1" } to { "PathRemovePrefix": "/web1" }

{
  "Routes": {
    "web-route1": {
      "ClusterId": "web-cluster1",
      "Match": {
        "Path": "/web1/{**catch-all}"
      },
      "Transforms": [
        { "PathRemovePrefix": "/web1" }
      ]
    },
    "web-route2": {
      "ClusterId": "web-cluster2",
      "Match": {
        "Path": "/web2/{**catch-all}"
      },
      "Transforms": [
        { "PathRemovePrefix": "/web2" }
      ]
    }
  },
  "Clusters": {
    "web-cluster1": {
      "Destinations": {
        "destination1": {
          "Address": "http://localhost:5135/"
        }
      }
    },
    "web-cluster2": {
      "Destinations": {
        "destination1": {
          "Address": "http://localhost:5022/"
        }
      }
    }
  }
}
ctyar
  • 931
  • 2
  • 10
  • 22