前端报错:

XMLHttpRequest cannot load http://localhost:8080/serviceA/api/serviceA/1337?cacheBuster=1470925389167.
The Access-Control-Allow-Origin header contains multiple values 'http://localhost:3000, http://localhost:3000', but only one is allowed. 
Origin 'http://localhost:3000' is therefore not allowed access.

解决方案:

情况1:配置了多次跨域,如在前端vue配置了一次跨域,后端spring zuul配置了一次跨域或nginx配置了一次跨越。此时只需要关闭某几种,留下一种即可。

情况2:单纯是的只配置了spring zuul一次跨域,还出现重复跨域,此时只需要在网关配置文件中加入:

zuul:
  ignored-headers: Access-Control-Allow-Credentials, Access-Control-Allow-Origin

情况2的原因:

zuul网关为了解决跨域问题,设置了response的Access-Control-Allow-Origin为客户端orgin,Access-Control-Allow-Origin:http://localhost:8080,然后服务网关访问微服务将response中的Access-Control-Allow-Origin:http://localhost:8080带了过去,微服务为了解决跨域,又在Access-Control-Allow-Origin中加了客户端orgin,Access-Control-Allow-Origin:http://localhost:8080,http://localhost:8080

更多推荐

解决Spring Cloud Zuul跨域时出现重复Access-Control-Allow-Origin或者Access-Control-Allow-Cred