Spring Boot Zuul hateoas REST响应在资源中具有直接服务链接 [英] Spring Boot Zuul hateoas REST response has direct service links in resource

查看:106
本文介绍了Spring Boot Zuul hateoas REST响应在资源中具有直接服务链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Zuul + Eureka + Spring Boot Service端点+ Hateoas响应配置.当我通过Zuul网关访问服务时,响应中的资源链接是指向服务端点的直接链接,难道它们不是网关链接吗?我在这里想念什么?

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?

网关端点: http://localhost:8762/catalog/products/10001 直接服务端点: http://localhost:8100/products/10001

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

Zuul的application.properties

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

网关端点上的实际响应: http://localhost:8762/catalog/products/10001

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

预期的响应应在href中具有网关URL

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

推荐答案

我遇到了这个问题,并通过

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

要点是您需要

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

并设置

server.use-forward-headers=true

这篇关于Spring Boot Zuul hateoas REST响应在资源中具有直接服务链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆