简体   繁体   English

KrakenD 包罗万象的路径

[英]KrakenD catchall path

I have two paths in KrakenD config: /city/toronto and /city/vancouver.我在 KrakenD 配置中有两条路径:/city/toronto 和 /city/vancouver。 I want to create another path /city/other that would catch every other city that would be provided.我想创建另一条路径 /city/other 来捕获将提供的所有其他城市。

I know at first glance one would say: make the city a path parameter or one would even say make the city a query parameter.我知道乍一看有人会说:将城市设为路径参数,甚至有人会说将城市设为查询参数。 I have considered these options and they are not viable.我考虑过这些选择,但它们不可行。

Is there a way in Krakend To define a catchall or fallback endpoint? Krakend 中有没有办法定义一个包罗万象或后备端点? I though wildcard could allow me to do this but I am not seeing how this would work.我虽然通配符可以让我这样做,但我不知道这是如何工作的。

In earlier versions of KrakenD this was not possible, but since 1.4 you can use routes that before were considered to be conflicting.在 KrakenD 的早期版本中这是不可能的,但是从 1.4 开始你可以使用之前被认为是冲突的路由。 The following example does exactly what you are expecting.以下示例完全符合您的预期。 Run with the -d flag:使用-d标志运行:

krakend run -d -c krakend.json where the content of the JSON file is: krakend run -d -c krakend.json其中 JSON 文件的内容是:

{
  "version": 2,
  "endpoints": [
    {
      "endpoint": "/city/vancouver",
      "backend": [
        {
          "url_pattern": "/__debug/vancouver",
          "host": [
            "http://localhost:8080"
          ]
        }
      ]
    },
    {
       "endpoint": "/city/toronto",
       "backend": [
         {
           "url_pattern": "/__debug/toronto",
           "host": [
             "http://localhost:8080"
           ]
         }
       ]
     },
    {
      "endpoint": "/city/{other}",
      "backend": [
        {
          "url_pattern": "/__debug/catchall",
          "host": [
            "http://localhost:8080"
          ]
        }
      ]
    }
  ]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM