我正在尝试在React应用程序和NodeJS应用程序之间设置云网关
下面是错误,我得到的ReactApp:
Access to XMLHttpRequest at 'http://localhost:8080/graphql' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
我已经尝试了下面的链接,因为可能是新版本的云网关不工作。
尝试# 1:
spring.cloud.gateway.globalcors.cors-configurations.[/**].allowedOrigins=*
spring.cloud.gateway.globalcors.cors-configurations.[/**].allowedMethods=*
有了这个,我得到标题问题,所以我添加:
spring.cloud.gateway.globalcors.cors-configurations.[/**].allowedHeaders=*
I am getting below error:
The 'Access-Control-Allow-Origin' header contains multiple values 'http://localhost:3000, *', but only one is allowed.
尝试# 2:
我尝试添加以下bean:
@Bean
Function<GatewayFilterSpec, UriSpec> brutalCorsFilters() {
return f -> f
.setResponseHeader("Access-Control-Allow-Origin", "*")
.setResponseHeader("Access-Control-Allow-Methods", "*")
.setResponseHeader("Access-Control-Expose-Headers", "*");
}
但仍然没有运气
回购:https://github.com/shah-smit/quizroulette-spring-cloud-api-gateway
请仔细检查您的配置,应该是您的配置导致了多个值,参考此& # 39; Access-Control-Allow-Origin& # 39;头文件包含多个值
也许你可以调试你的代码,找出'Access-Control-Allow-Origin'变成两个值的地方。