【问题标题】:How to avoid port in Downstream url in ocelot?如何避免ocelot下游url中的端口?
【发布时间】:2019-12-25 15:31:31
【问题描述】:

端口被添加到下游 url。我想访问托管在 heroku 中的微服务。需要避开港口。 请帮忙。

它在本地开发环境中工作。但在 Heroku 中部署后无法正常工作。

{
  "ReRoutes": [
    {
      "DownstreamPathTemplate": "/api/{catchAll}",
      "DownstreamScheme": "https",
      "DownstreamHostAndPorts": [
        {
          "Host": "catalogapi-pinaki.herokuapp.com"
        }
      ],
      "UpstreamPathTemplate": "/cat-logApi/{catchAll}"

    }

  ],
  "GlobalConfiguration": {
    "BaseUrl": "http://localhost"
  }
}

下游 URL 应为“https://catalogapi-pinaki.herokuapp.com/api/CatalogApi/GetAllItems”。

错误: message: 下游 url 为https://catalogapi-pinaki.herokuapp.com:56084/api/CatalogApi/GetAllItems

my Error message

【问题讨论】:

    标签: c# heroku ocelot


    【解决方案1】:

    您是否尝试强制使用默认端口?您可以使用“DownstreamHostAndPorts”中的端口属性指定端口,如下所示:

         {
            "ReRoutes": [
                {
                "DownstreamPathTemplate": "/api/{catchAll}",
                "DownstreamScheme": "https",
                "DownstreamHostAndPorts": [
                    {
                        "Host": "catalogapi-pinaki.herokuapp.com",
                        "Port": 443
                    }
                ],
                "UpstreamPathTemplate": "/cat-logApi/{catchAll}"
                }
            ],
            "GlobalConfiguration": {
                "BaseUrl": "http://localhost"
            }
        }
    

    【讨论】:

      【解决方案2】:

      我们也面临同样的问题。我们使用 FIX 2 修复了问题。

      修复 1: services.AddOcelot(Configuration.GetSection("OcelotSettings")) .AddDelegatingHandler(true);

      在 OcelotRerouteHandler 中,您可以替换您的 url 并构造新的 httprequestmessage。 参考:https://ocelot.readthedocs.io/en/latest/features/delegatinghandlers.html

      修复2:

      "DownstreamPathTemplate": "/subdomain/api/{catchAll}"

      “主机”:“catalogapi-pinaki.herokuapp.com”,

      如果您有任何子域,请不要将其添加到 HOST 添加到 DownstreamPathTemplate。 对于 https 端口可以是 443。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-01-27
        • 2020-07-06
        • 2013-01-16
        • 1970-01-01
        • 2021-02-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多