YARP - 基于正则表达式的路由

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

是否可以在 Match-Path-rules 中使用正则表达式来匹配一般更广泛的 url 模式并能够匹配非常具体的模式。我不想使用

{**catch-all}
但例如像
/api/\w{1,3}-\d{1,9}
...

这样的普通正则表达式

这可以通过 Yarp 以某种方式实现吗?

"Match": {
        "Path": "<Regular expressions here or ?>"
    }
.net-core reverse-proxy ms-yarp
2个回答
1
投票

你可以这样写:

"Match": {
   "Path": "/api/{path:regex(\\w{{1,3}}-\\d{{1,9}})}"
}

"Match": {
   "Path": "/api/{folder1:regex(^\\w{{1,3}}$)}-{folder2:regex(^\\d{{1,9}}$)}"
}

0
投票

@drlivsi

像这样的事情怎么样: 路径:“/{path:regex(^(v1|beta)$}/bpm/{**path}”

可行吗?

我想支持我的 API 的 v1 和 beta 版本

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