gpt4 book ai didi

spring-boot-actuator - spring cloud gateway,你能排除路径吗(做一个全局的!=)

转载 作者:行者123 更新时间:2023-12-05 06:30:02 25 4
gpt4 key购买 nike

我希望有人能在这里提供一些想法。我正在使用 spring cloud gateway 的一些示例应用程序并浏览文档,但我没有看到任何路由到自身或进行全局忽略的方法。这里的想法是,有些路径总是需要指向自己,比如执行器,而其他路径可能需要一个全局 block (可能出于安全原因,比如你发现了一个严重的漏洞,需要禁用对特定资源)。目前据我所知,没有办法做到这一点,但我希望我是错的!

我已将应用设置为执行器在端口 8081 上运行,服务器在 8080 上运行。我有两个简单的规则:

  - id: local_test_1
uri: http://localhost:80
order: 9000
predicates:
- Path=/echo
# =====================================
- id: local_test_2
uri: ${test.uri}
order: 10000
predicates:
- Path=/**

但是通用/** 确保对 localhost:8081/actuator/* 的任何调用也被路由到 uri。如何从路由规则中免除管理端口,以便服务器自己处理请求?

我认为像 Path!=${management.server.port}/* 这样的默认过滤器可能有效,但似乎不支持 !=。

最佳答案

我在使用默认路由时遇到了同样的问题,但还需要从类路径提供自定义的注销后页面。默认路由将处理请求而不是网关本身。在没有默认路由的情况下,logout.html 得到了正确的服务。

我最终将默认路由移动到 Java bean 并像这样使用流畅的 API:

@Bean
public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
return builder.routes()
.route("default", r -> r
.order(Ordered.LOWEST_PRECEDENCE)
.path("/**")
.and().not(p -> p.path("/logout.html", "/logout.css"))
.uri("http://localhost:8080")
)
.build();
}

如果有人知道在 .yml 配置文件中进行否定的方法那将是理想的,但我还没有在任何文档中找到这样的示例。

关于spring-boot-actuator - spring cloud gateway,你能排除路径吗(做一个全局的!=),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52841711/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com