【发布时间】:2022-10-19 18:03:32
【问题描述】:
我有一个使用 Spring Cloud Gateway 在本地运行的 React 应用程序。我收到此错误:
adminLogin:1 Access to XMLHttpRequest at 'http://localhost:9191/admin/authenticate' from origin 'http://localhost:3000' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header contains multiple values 'http://localhost:3000, http://localhost:3000', but only one is allowed.
9191是我的云网关端口号 我的云网关yml文件:
server:
port: 9191
spring:
application:
name: API-GATEWAY
cloud:
gateway:
globalcors:
corsConfigurations:
'[/**]':
allowedOrigins: "http://localhost:3000/"
allowedMethods:
- GET
- POST
- PUT
- DELETE
routes:
- id: ADMIN-SERVICE
uri: lb://ADMIN-SERVICE
predicates:
- Path=/admin/**
- id: CUSTOMER-SERVICE
uri: lb://CUSTOMER-SERVICE
predicates:
- Path=/customer/**
- id: DEALER-SERVICE
uri: lb://DEALER-SERVICE
predicates:
- Path=/dealer/**
- id: VENUE-SERVICE
uri: lb://VENUE-SERVICE
predicates:
- Path=/venue/**
eureka:
client:
fetch-registry: true
register-with-eureka: true
service-url:
defaultZone: http://localhost:8761/eureka/
instance:
hostname: localhost
我该如何解决这个问题?
【问题讨论】:
标签: java reactjs spring spring-boot spring-cloud-gateway