我有一个使用在本地运行的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我怎样才能解决这个问题?
发布于 2022-10-19 10:03:32
面对同样的问题,反应应用。似乎你错过了默认过滤器。我已经在春云网关中对cors进行了以下配置:-
spring:
cloud:
gateway:
default-filters:
- DedupeResponseHeader=Access-Control-Allow-Credentials Access-Control-Allow-Origin
globalcors:
corsConfigurations:
'[/**]':
allowedOrigins: "*"
allowedMethods: "*"
allowedHeaders: "*"
routes:
- id: portalModuleSpring-Bootv2.7.4,Java v11,Spring版本v2021.0.4
https://stackoverflow.com/questions/73305627
复制相似问题