Search code examples
springspring-bootnetflix-eurekanetflix-zuulspring-hateoas

Spring Boot Zuul hateoas REST response has direct service links in resource


I have Zuul + Eureka + Spring Boot Service Endpoint + Hateoas response configuration. When I access the service through Zuul Gateway, the resource links in the response are direct links to the service endpoints, shouldn't they be the Gateway links? What am i missing here?

Gateway Endpoint : http://localhost:8762/catalog/products/10001 Direct Service Endpoint : http://localhost:8100/products/10001

application.properties for Zuul

spring.application.name=zuul-server
eureka.client.service-url.default-zone=http://localhost:8761/eureka/

# Map paths to services
zuul.routes.catalog-service=/catalog/**
zuul.addProxyHeaders=true

Actual Response on Gateway Endpoint : http://localhost:8762/catalog/products/10001

{
  "title" : "The Title",
  "description" : "The Description",
  "brand" : "SOME BRAND",
  "price" : 100,
  "color" : "Black",
  "_links" : {
    "self" : {
      "href" : "http://localhost:8100/products/10001"
    }
  }
}

Expected Response should have Gateway URL in href

{
  "title" : "The Title",
  "description" : "The Description",
  "brand" : "SOME BRAND",
  "price" : 100,
  "color" : "Black",
  "_links" : {
    "self" : {
      "href" : "http://localhost:8762/catalog/products/10001"
    }
  }
}

Solution

  • I've got this issue and resolved it via this post on github

    The gist is

    spring-boot <=2.1

    @Bean
    ForwardedHeaderFilter forwardedHeaderFilter() {
        return new ForwardedHeaderFilter();
    }
    

    spring-boot >= 2.2

    server.use-forward-headers=true