spring cloud gateway 跨域配置

  • Post author:
  • Post category:其他

springboot 版本:2.3.3

我们可以通过配置网关来控制CORS行为,全局CORS配置是 Spring Framework CorsConfiguration模式的URL MAP。

spring:
  cloud:
    gateway:
      globalcors:
        cors-configurations:
          '[/**]':
            allowedOrigins: "https://docs.spring.io"
            allowedHeaders: "*"
            allowedMethods:
            - GET

这是官方说明文档中推荐的方法。

注意
网上很多文章说这个方法不行,其实就是缺少了allowedHeaders这一项配置。

如果配置没有生效,注意看日志输出,能快速定位到问题

更多配置请看 spring cloud gateway使用说明


版权声明:本文为xgw1010原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。