-1

I have a simple spring-cloud-gateway-mvc gateway where I have configured the cors through configuration which does not work.

spring:
  cloud:
    gateway:
      mvc:
        routes:
          - id: api-routes
            uri: http://localhost:8081
            predicates:
              - Path=/api/v1.0/access-token,/api/v1.0/inquiry
              - Method=POST,OPTIONS
            filters:
              - name: DedupeResponseHeader # Remove duplicate headers
                args:
                  name: Access-Control-Allow-Credentials Access-Control-Allow-Origin
              - name: StripPrefix # Remove the prefix '/my-gateway' from the request
                args:
                  parts: 1
              - name: PrefixPath # Add the prefix '/api-server' to the request
                args:
                  prefix: /api-server
            metadata:
              cors:
                allowedOrigins: '*'
                allowedMethods: '*'
                allowedHeaders: '*'
                allowCredentials: true
                maxAge: 30

I tried adding cors mapping as mentioned in spring docs, still not works.

@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("**/**")
            .allowedOrigins("*")
            .allowedMethods("*")
            .allowedHeaders("*")
            .allowCredentials(true)
            .maxAge(3600);
    }
}

I am still getting 403 with Preflight request.

enter image description here

Any help is really appreciated.

0