1

端口被添加到下游 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 ”。

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

我的错误信息

4

2 回答 2

1

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

     {
        "ReRoutes": [
            {
            "DownstreamPathTemplate": "/api/{catchAll}",
            "DownstreamScheme": "https",
            "DownstreamHostAndPorts": [
                {
                    "Host": "catalogapi-pinaki.herokuapp.com",
                    "Port": 443
                }
            ],
            "UpstreamPathTemplate": "/cat-logApi/{catchAll}"
            }
        ],
        "GlobalConfiguration": {
            "BaseUrl": "http://localhost"
        }
    }
于 2019-09-11T10:11:11.677 回答
0

我们也面临同样的问题。我们使用 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。

于 2019-11-29T12:31:02.103 回答