跨域问题,出现多个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
spring: cloud: gateway: globalcors: corsConfigurations: '[/**]': allowedOrigins: "*" allowedMethods: "*" allowedHeaders: "*" default-filters[0]: DedupeResponseHeader=Access-Control-Allow-Origin Access-Control-Allow-Credentials,RETAIN_FIRST
具体可以看这个类的源码参考:DedupeResponseHeaderGatewayFilterFactory
124 篇文章
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!