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

两盒软妹~` 提交于 2019-12-08 04:54:53

问题


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"
    }
  }
}

回答1:


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

The gist is that you need

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

and set

server.use-forward-headers=true


来源:https://stackoverflow.com/questions/57094913/spring-boot-zuul-hateoas-rest-response-has-direct-service-links-in-resource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!