【发布时间】:2022-01-04 02:42:40
【问题描述】:
我有一个在本地运行的 React 应用程序,并且 Spring Cloud Gateway 作为 BE 在远程 VPS 上运行。我收到此错误:
Access to XMLHttpRequest at 'http://11.1.1.5:8080/api/business_structure' 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.
我尝试在 Spring Cloud Gateway 中配置 CORS:
application.yml
spring:
application:
name: service
cloud:
gateway:
globalcors:
cors-configurations:
'[/*]':
allowedOrigins:
- "*"
- "http://localhost:3000"
allowedMethods:
- GET
- POST
但它不起作用。我很感兴趣为什么在我的情况下会出现此错误? FE 和 BE 在不同的主机上运行。
我该如何解决这个问题?
【问题讨论】:
标签: reactjs spring spring-cloud spring-cloud-gateway