gateway 報錯 allowedOrigins cannot contain the special

FH-Admin發表於2021-09-01
java.lang.IllegalArgumentException: When allowCredentials is true, allowedOrigins cannot contain 
the special value "*" since that cannot be set on the "Access-Control-Allow-Origin" response 
header. To allow credentials to a set of origins, list them explicitly or consider using "allowedOriginPatterns" instead.
    at org.springframework.web.cors.CorsConfiguration.validateAllowCredentials(CorsConfiguration.java:460)

    Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
Error has been observed at the following site(s):
    |_ checkpoint ⇢ org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain][from www.fhadmin.cn]

問題原因,新版本的gateway 取消了allowedOrigins, 對應的變更為 allowedOriginPatterns

配置修改為:

#--------gateway配置---fhadmin.cn-----
#使用服務發現路由
spring.cloud.gateway.discovery.locator.enabled=true
#服務路由名小寫
spring.cloud.gateway.discovery.locator.lower-case-service-id=true
#跨域配置(java www.fhadmin.cn)
spring.cloud.gateway.globalcors.corsConfigurations.[/**].allowedOriginPatterns=*
spring.cloud.gateway.globalcors.corsConfigurations.[/**].allowedHeaders=*
spring.cloud.gateway.globalcors.corsConfigurations.[/**].allowedMethods=*
spring.cloud.gateway.globalcors.corsConfigurations.[/**].allowCredentials=true
本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章