0

I am new to Ocelot API Gateway and trying to figure out how to perform a response host rewrite?

My ocelot api gateway is hosted on localhost:5000, the downstream server is on another host example.com. I am able to proxy from localhost:5000 to example.com, however, when example.com sends a response I get redirected to example.com. I need to stay within one domain (localhost:5000).

Any help is appreciated

{
"ReRoutes": [
    {
    "DownstreamPathTemplate": "/example/{all}",
    "DownstreamScheme": "https",
    "DownstreamHostAndPorts": [
        {
            "Host": "example.com",
            "Port": 443
        }
    ],
    "UpstreamPathTemplate": "/example/{all}",
    }
],
"GlobalConfiguration": {
    "BaseUrl": "https://localhost:5000"
 }
}
Jonathan
  • 73
  • 2
  • 8

1 Answers1

0

A bit late, but I think you need a "DownstreamHeaderTransform", which will change back example.com to localhost:9000. (not sure if the port will be mapped correctly). In our use case, we use the IP address of the downstream server, and then map that back to the host that the outside world sees. For you, try something along these lines:

{
"ReRoutes": [
    {
    "DownstreamPathTemplate": "/example/{all}",
    "DownstreamScheme": "https",
    "DownstreamHostAndPorts": [
        {
            "Host": "example.com",
            "Port": 443
        }
    ],
    "DownstreamHeaderTransform": {
        "Referrer": "https://example.com, https://localhost:5000",
        "Host": "example.com, localhost:9000",
        "Origin": "https://example.com, https://localhost:5000"
    },
    "UpstreamPathTemplate": "/example/{all}",
    }
],
"GlobalConfiguration": {
    "BaseUrl": "https://localhost:5000"
 }
}

Personally, I found Ocelot to be rather finiky, and would try Kestrel instead.

TomEberhard
  • 907
  • 10
  • 11