无法合并 Ocelot 配置文件

Ens*_*glu 7 ocelot

根据文档,我尝试合并我的配置文件,以便它们更具可读性。然而,生成的 ocelot.json 文件并不像预期的那样。我的文件夹结构如下:

文件夹结构

下面是这个的文本表示:

.
??? Ocelot route configs
    ??? ocelot.pokemon.json
    ??? ocelot.tweet.json
    ??? ocelot.weather.json
Run Code Online (Sandbox Code Playgroud)

ocelot.pokemon.json 文件如下所示(其他类似):

{
  "Routes": [
    {
      "DownstreamPathTemplate": "/api/v2/pokemon",
      "DownstreamScheme": "https",
      "DownstreamHostAndPorts": [
        {
          "Host": "pokeapi.co",
          "Port": 443
        }
      ],
      "UpstreamPathTemplate": "/api/pokemon",
      "UpstreamHttpMethod": [ "GET" ],
      "AuthenticationOptions": {
        "AuthenticationProviderKey": "MyTestKey",
        "AllowedScopes": []
      }
    },
    {
      "DownstreamPathTemplate": "/api/v2/pokemon/ditto",
      "DownstreamScheme": "https",
      "DownstreamHostAndPorts": [
        {
          "Host": "pokeapi.co",
          "Port": 443
        }
      ],
      "UpstreamPathTemplate": "/api/pokemon/ditto",
      "UpstreamHttpMethod": [ "GET" ]
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

生成的 ocelot.json 文件如下所示:

{
  "Routes": [
  ],
  "DynamicRoutes": [
  ],
  "Aggregates": [
  ],
  "GlobalConfiguration": {
    "RequestIdKey": null,
    "ServiceDiscoveryProvider": {
      "Scheme": null,
      "Host": null,
      "Port": 0,
      "Type": null,
      "Token": null,
      "ConfigurationKey": null,
      "PollingInterval": 0,
      "Namespace": null
    },
    "RateLimitOptions": {
      "ClientIdHeader": "ClientId",
      "QuotaExceededMessage": null,
      "RateLimitCounterPrefix": "ocelot",
      "DisableRateLimitHeaders": false,
      "HttpStatusCode": 429
    },
    "QoSOptions": {
      "ExceptionsAllowedBeforeBreaking": 0,
      "DurationOfBreak": 0,
      "TimeoutValue": 0
    },
    "BaseUrl": null,
    "LoadBalancerOptions": {
      "Type": null,
      "Key": null,
      "Expiry": 0
    },
    "DownstreamScheme": null,
    "HttpHandlerOptions": {
      "AllowAutoRedirect": false,
      "UseCookieContainer": false,
      "UseTracing": false,
      "UseProxy": true,
      "MaxConnectionsPerServer": 2147483647
    },
    "DownstreamHttpVersion": null
  }
}
Run Code Online (Sandbox Code Playgroud)

如您所见,我定义的路由没有添加。我尝试在互联网上查找此特定问题,但找不到任何内容。我不知道我做错了什么,将不胜感激。

小智 6

由于您的不同路由配置文件位于一个文件夹中,您应该确保调用 AddOcelot 方法的正确重载。在这种情况下,应使用包含路由文件的文件夹名称调用该方法。

例如:

config.AddOcelot("Ocelot route configs", hostingContext.HostingEnvironment)
Run Code Online (Sandbox Code Playgroud)