ThreeMammals / Ocelot

.NET API Gateway
https://www.nuget.org/packages/Ocelot
MIT License
8.31k stars 1.63k forks source link

DownstreamHostAndPorts alias #692

Open mariotacke opened 5 years ago

mariotacke commented 5 years ago

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

golavr commented 4 years ago

@philproctor any update on this enhancement? this feature will save a lot of configuration changes as @mariotacke mentioned thanks

gao-artur commented 3 years ago

Check my answer on SO. It does exactly what you are asking for https://stackoverflow.com/a/63601248/2557855

NicoJuicy commented 2 years ago

@gao-artur I had to put the configuration in my appsettings and not in the ocelot.json to make it work. But it solved my problem, thanks!

raman-m commented 1 year ago

The issue has been accepted due to ready PR #1353 :

All interested parties are welcome to review the code. But the spec above is not final, the discussion can continue...

mariotacke commented 1 year ago

Thanks all for finally addressing this. However, I must say I've moved on from this project since I filed this issue it in 2018. Going to un-assign myself.

raman-m commented 1 year ago

@mariotacke commented on Aug 11:

Sad to hear that! What gateway project has your team migrated to?