小编Pri*_*wal的帖子

微服务架构:CORS 配置导致访问控制允许来源标头包含多个值

我正在开发一个 Spring Boot 应用程序。其中有API-Gateway和三个微服务。当我从 UI 调用 API 时,它会抛出 CORS 错误。

错误:

访问控制允许来源标头包含多个值,但只允许一个

在此输入图像描述

我已经在 API-Gateway 的 application.yml 中配置了 cors。

spring:
    application:
        name: api-gateway
    cache:
        type: redis
    redis:
        host: 'http://localhost'
        port: 6379
    cloud:
        gateway:
            globalcors:
                corsConfigurations:
                '[/**]':
                allowedOrigins: "*"
                allowedMethods: "*"
                allowedHeaders: "*"
    eureka:
        client:
            eureka-server-d-n-s-name: my.dns
            eureka-service-url-Context: eureka
            fetch-registry: false
            region: ap-south-1b
            register-with-eureka: false
            use-dns-for-fetching-service-urls: true
        datacenter: cloud
    ribbon:
        eureka:
            enabled: false
    server:
        port: 8765
    zuul:
        routes:
            order-service:
                url: 'http://localhost:8088'
            product-service:
                url: 'http://localhost:8084'
            user-service:
                url: 'http://localhost:8082'
Run Code Online (Sandbox Code Playgroud)

除此之外,我还在每个微服务中配置了 CORS。如果我直接调用微服务,而不是通过 API-Gateway 调用 API,它工作得很好。

java cors spring-boot microservices api-gateway

4
推荐指数
1
解决办法
7267
查看次数

标签 统计

api-gateway ×1

cors ×1

java ×1

microservices ×1

spring-boot ×1