Spring Cloud Gateway 路由到自身

Moh*_*gal 8 cloud spring routes gateway


我在 Spring Cloud Gateway 的实现中有一个场景(仅供参考,调用该服务自定义 api 网关)。在此“自定义 API 网关”中,我想定义路由、过滤器、谓词并将请求转发到“自定义 API 网关”中的自定义端点?有办法实现吗?除了转发到“自定义 api 网关”中的 URI 之外,一切正常

这是一个例子

id: UpdateUser
uri:  SHOULD NOT GO DOWNSTREAM (endpoint is in 'custom api gateway')
predicates:
 - path=/api/users
filters:
 - ValidateSession
Run Code Online (Sandbox Code Playgroud)

谢谢塞吉

boh*_*der 2

您可以在 Spring Cloud Gateway 中定义一些控制器并编写路由将请求路由到这些控制器,但您应该添加 uri 更改过滤器,例如prefixPathstripPrefix将 uri 部分更改为不同的过滤器。

如果不更改 uri,请求将导致413 请求实体太大错误代码,如果打开调试级别日志,您将看到网关正在一遍又一遍地将此请求传递给自身。