-
Hi, We use Ocelot to put some services behind a gateway. We are using version 22.0.1 and I tried to update Ocelot to version 23.2.2 but I have some problems using placeholders in routing. In our services we have endpoints that we don't want to expose through the gateway. For example, we have routes following similar patterns.
I would like to expose routes 1, 2 and 3 in Ocelot, but hide routes 4 and 5. At the time we didn't find a way to deny routes using patterns. So we found a solution with patterns. {
"UpstreamHttpMethod": [ "Get" ],
"UpstreamPathTemplate": "/v2/Products",
"DownstreamPathTemplate": "/v1/Products",
"DownstreamScheme": "https",
},
{
"UpstreamHttpMethod": [ "Post" ],
"UpstreamPathTemplate": "/v2/Products/{id}/SomeAction",
"DownstreamPathTemplate": "/v1/Products/{id}/SomePublicAction",
"DownstreamScheme": "https",
},
{
"UpstreamHttpMethod": [ "Get" ],
"UpstreamPathTemplate": "/v2/Products/{id}",
"DownstreamPathTemplate": "/v1/Products/{id}",
"DownstreamScheme": "https",
},
{
"UpstreamHttpMethod": [ "Get", "Post" ],
"UpstreamPathTemplate": "/v2/Products/{id}/{all}",
"DownstreamPathTemplate": "/unknown",
"DownstreamScheme": "https",
} With the last item in the configuration you can see that we redirect everything else to a route we know it doesn't exist (i.e. /unknown). This way, we only expose the endpoints we want and everything else isn't because the underlying service returns a status 404. In version 23.2.2 there is the empty placeholder feature that was added, and I think it breaks the configuration we added. Now, the last two items in the configuration comes into conflict. Depending on the order in the list, either all routes under /Products/{id} are exposed or none of them. Is there a better way to achieve what we want? In a real-life example, we can have more endpoints that we don't want to expose. Thank you for your help. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi Alexis!
We apologize, but this feature will be a permanent part of Ocelot. You need to adapt/redefine your routes.
The solution involves using the Routing Priority feature to assign the highest priority to the last "/unknown" route. The remaining routes should be assigned a lower priority and can be consolidated into a single Catch All route. The solution{
"UpstreamHttpMethod": [ "Get", "Post" ],
"UpstreamPathTemplate": "/v2/Products/{id}/{all}",
"DownstreamPathTemplate": "/unknown",
"DownstreamScheme": "https",
"Priority": 1 // higher priority
},
{
"UpstreamHttpMethod": [ "Get", "Post" ],
"UpstreamPathTemplate": "/v2/Products/{catchAll}",
"DownstreamPathTemplate": "/v1/Products/{catchAll}",
"DownstreamScheme": "https",
"Priority": 0
} But this solution should be tested first. Hope it helps! |
Beta Was this translation helpful? Give feedback.
Hi Alexis!
Welcome to Ocelot world! 🐯
We apologize, but this feature will be a permanent part of Ocelot. You need to adapt/redefine your routes.
The solution involves using the Routing Priority feature to assign the highest priority to the last "/unknown" route. The remaining routes should be assigned a lower priority and can be consolidated into a single Catch All route.
The solution
{ "Upstrea…