ThreeMammals/Ocelot

DownstreamHostAndPorts alias

開放

#692 建立於 2018年11月16日

 (8 則留言) (8 個反應) (1 位負責人)C# (1,617 個分叉)batch import
Configurationhelp wantedlarge effortmedium effortproposal

倉庫指標

星標
 (8,137 顆星)
PR 合併指標
 (平均合併 44天 17小時) (30 天內合併 6 個 PR)

描述

My team and I are test-driving Ocelot for a new project. We are wondering if it is possible to alias the DownstreamHostAndPorts somehow without having to repeat it for many endpoints. This is especially important to us when we think about overriding host and port per environment.

For example, for development purposes, we want to have Host and Port set to localhost and 5005, but for staging and production to a different host name and port. I understand that this is possible to do via override, but we'd rather not duplicate the entire definition again.

We'd like to define multiple hosts and ports in the global configuration and reference them in the downstream host and ports section.

Example:

"GlobalConfiguration": {
  "BaseUrl": "https://our-system.net/api",
  "RequestIdKey": "X-Request-Id",
  "HostAndPorts": [
    {
      "Alias": "ServiceA",
      "Host": "localhost",
      "Port": "5005"
    }
  ]
}

Then, in the "ReRoutes" config, we'd use it instead of the host definition:

{
  "ReRoutes": [
    // other config
    "DownstreamHostAndPorts": [
      {
        "UseAlias": "ServiceA"
      }
    ]
  ]
}

Is this a use case you have come across? I guess, as a workaround, we could define host names in the hosts file of the system, but that requires all devs to have the same entries.

Specifications

  • Version: 12.0.1
  • Platform: dotnet core 2.1.5

貢獻者指南