Angular 使用 Springboot 的 API 网关中的 CORS 问题

问题描述 投票:0回答:1

我在 Springboot 中使用 API 网关时遇到 CORS 配置问题。我想做的是通过 API 网关使用我的微服务中的方法。 这是角度误差: API网关代码:

@Configuration
@EnableWebFluxSecurity
public class SecurityConfig {

    @Bean
    public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity serverHttpSecurity) {
        return serverHttpSecurity.csrf(ServerHttpSecurity.CsrfSpec::disable)
                .authorizeExchange(exchange -> exchange.pathMatchers("/eureka/**","/users/add-user")
                        .permitAll()
                        .anyExchange().authenticated()
                )


        .oauth2ResourceServer((oauth) -> oauth
                        .jwt(Customizer.withDefaults()))
                .build();
    }
}

还有一个问题,我是否应该只在 API 网关中实现一次 CORS 配置?或者我应该在每个使用的微服务中实现它?

我尝试通过 API 网关使用 Angular 中的微服务方法。

java angular spring-boot microservices api-gateway
1个回答
0
投票

即使在最好的日子里,CORS 也是一个令人头疼的问题。使用 AWS 时情况会更糟。

因此,请阅读您需要在此处配置的内容 - https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html

你的问题根本没有意义。所以我只能对这个问题做一个基本的回答。我建议尝试更多地了解 CORS 的客户端/服务器影响以及如何处理的技术。

© www.soinside.com 2019 - 2024. All rights reserved.