springcloud gateway的跨域问题解决;

# 这一段前面的配置是处理跨域的,本文处理重复header的请看最后一条配置 spring.cloud.gateway.globalcors.cors-configurations.[/**].allow-credentials=true spring.cloud.gateway.globalcor...
跨域问题,出现多个Access-Control-Allow-Origin:为* 或者其他的问题解决方案如下:亲测有效;

# 这一段前面的配置是处理跨域的,本文处理重复header的请看最后一条配置
spring.cloud.gateway.globalcors.cors-configurations.[/**].allow-credentials=true
spring.cloud.gateway.globalcors.cors-configurations.[/**].allowed-headers[0]=*
spring.cloud.gateway.globalcors.cors-configurations.[/**].allowed-methods[0]=*
spring.cloud.gateway.globalcors.cors-configurations.[/**].allowed-origins[0]=http://localhost:8080
spring.cloud.gateway.globalcors.cors-configurations.[/**].max-age=1800
# 相同header多个值时的处理方式,三种规则可选(RETAIN_FIRST|RETAIN_UNIQUE|RETAIN_LAST)
spring.cloud.gateway.default-filters[0]=DedupeResponseHeader=Access-Control-Allow-Origin Access-Control-Allow-Credentials, RETAIN_FIRST

yml配置如下:

spring:
  cloud:
    gateway:
      globalcors:
        corsConfigurations:
          '[/**]':
            allowedOrigins: "*"
            allowedMethods: "*"
            allowedHeaders: "*"
      default-filters[0]: DedupeResponseHeader=Access-Control-Allow-Origin Access-Control-Allow-Credentials,RETAIN_FIRST


具体可以看这个类的源码参考:DedupeResponseHeaderGatewayFilterFactory 



  • 发表于 2020-12-04 20:17
  • 阅读 ( 4513 )
  • 分类:Java

0 条评论

请先 登录 后评论
不写代码的码农
威猛的小站长

124 篇文章

作家榜 »

  1. 威猛的小站长 124 文章
  2. Jonny 65 文章
  3. 江南烟雨 36 文章
  4. - Nightmare 33 文章
  5. doublechina 31 文章
  6. HJ社区-肖峰 29 文章
  7. 伪摄影 22 文章
  8. Alan 14 文章