spring-cloud / spring-cloud-gateway

An API Gateway built on Spring Framework and Spring Boot providing routing and more.
http://cloud.spring.io
Apache License 2.0
4.52k stars 3.32k forks source link

How to use cros in springCloud gateway!!! #1767

Closed zhaogituser closed 4 years ago

zhaogituser commented 4 years ago

this is my configuration.

@Bean
    public CorsWebFilter corsFilter() {
        CorsConfiguration config = new CorsConfiguration();
        config.addAllowedMethod("*");
        config.addAllowedOrigin("*");
        config.addAllowedHeader("*");
       config.addAllowedHeader("ThirdAuthorization");
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
        source.registerCorsConfiguration("/**", config);

        return new CorsWebFilter(source);
    }

Ajax

var settings = {
                    "processData": false,
                    // "crossDomain": true,
                    "url": "http://ip/auth/check",
                    "data": param,
                    "method": "POST",
                    "contentType": false,
                    "headers": {
                        'Access-Control-Allow-Headers': 'ThirdAuthorization',
                        'ThirdAuthorization': 'KhcmMl4GcT85-RP5BJIByGo9IIJlTO6JMSbXMIrmVl3gr3S65zc%2Bxg__'
                    }
                }

request result: cros error Request header field access-control-allow-headers is not allowed by Access-Control-Allow-Headers in preflight response.

ajax error credit/auth/check net::ERR_FAILED

How should i do . I added a custom header in the request .ThirdAuthorization

spencergibb commented 4 years ago

See https://cloud.spring.io/spring-cloud-static/spring-cloud-gateway/2.2.0.RELEASE/reference/html/#cors-configuration

spring-projects-issues commented 4 years ago

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-projects-issues commented 4 years ago

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.