我们可以根据模式来匹配路线吗

问题描述 投票:0回答:1

我们使用 YARP 将请求路由到不同的端点。我们有一个要求,任何以“/secured”开头的 URL 都应该转发到特定的集群端点。例如以下所有路径都需要发送到cluster1

  1. /安全
  2. /安全/
  3. /安全/xyz
  4. /安全/xyz/abc
  5. /安全xyz
  6. /安全xyz/
  7. /securedxyz/abc

为了实现这一目标,我们配置如下路线:

{
 "AllowedHosts": "*",
 "ReverseProxy": {
   "Routes": {
     "route1" : {
       "ClusterId": "cluster1",
       "Match": {
         "Path": "/secured{any1}"
       }
     },
     "route2" : {
       "ClusterId": "cluster1",
       "Match": {
         "Path": "/secured{any1}/{*any}"
       }
     },
    "route3" : {
       "ClusterId": "cluster1",
       "Match": {
         "Path": "/secured/{*any}"
       }
     }
   },
   "Clusters": {
     "cluster1": {
       "Destinations": {
         "destination1": {
           "Address": "https://secured.com/"
         }
       }
     }
   }
 }
}

我们可以将路径配置为匹配上面指定的所有路由的模式吗?我已经尝试过下面的配置,但它不起作用。我想减少路由规范的数量,使配置更短。

    "Path": "/secured(.*)"
asp.net-core ms-yarp
1个回答
0
投票

用途:

/secured/{**catch-all}

这将与 /secured 之后的 URL 其余部分匹配

© www.soinside.com 2019 - 2024. All rights reserved.