1

I have the following file ocelot.json and I want to change the Host object of each route configured inside the file through a variable. I want to change the localhost to the correct hostname through a variable.

"Routes": [
    //Parámetricas
    {
      "UpstreamPathTemplate": "/api/ClasificacionEquipo",
      "UpstreamHttpMethod": [ "GET" ],
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": 19007
        }
      ],
      "DownstreamPathTemplate": "/api/ClasificacionEquipo",
      "FileCacheOptions": {
        "TtlSeconds": 3600,
        "Region": "parametricas"
      }
    },
    {
      "UpstreamPathTemplate": "/api/ClasificacionEquipo/{id}",
      "UpstreamHttpMethod": [ "GET" ],
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": 19007
        }
      ],
      "DownstreamPathTemplate": "/api/ClasificacionEquipo/{id}",
      "FileCacheOptions": {
        "TtlSeconds": 300,
        "Region": "parametricas"
      }
    }
]

I create the following variable but it doesn't take me the change: Routes.DownstreamHostAndPorts.Host.

I have also tried as follows: Routes.*.DownstreamHostAndPorts.0.Host

And it hasn't worked for me

2 Answers 2

0

If you want to do file transformation of JSON files in ADO we have the FileTransform@1 task

 - task: FileTransform@1
      displayName: Transform Json File
      inputs:
        folderPath: '$(System.DefaultWorkingDirectory)/<path-to-your-file>'
        fileType: 'json'
        targetFiles: '<your-file-name>.json'

More info on this https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/file-transform?view=azure-devops

Sign up to request clarification or add additional context in comments.

Comments

0
The answer is 

Routes.0.DownstreamHostAndPorts.0.Host

Routes.0.DownstreamHostAndPorts.1.Host

Routes.1.DownstreamHostAndPorts.0.Host

Routes.1.DownstreamHostAndPorts.1.Host

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.