title: Spring Cloud Gateway + Keycloak CORS not working
body: <p>I developed backend microservice application using Spring Boot and put API Gateway in front of microservices. To authenticate users I am using Keycloak.
  Right now I am developing frontend application using Svelte, I configured my application.yml in gateway application like this:</p>
  <pre><code>spring:
    cloud:
      gateway:
        default-filters:
          - TokenRelay
          - DedupeResponseHeader=Access-Control-Allow-Credentials Access-Control-Allow-Origin
        globalcors:
          cors-configurations:
            '[/**]':
              allowedOrigins: &quot;*&quot;
              allowedMethods: &quot;*&quot;
              allowedHeaders: &quot;*&quot;
          add-to-simple-url-handler-mapping: true
  </code></pre>
  <p>However, when I am trying to send AJAX request I get the CORS error.</p>
  <p>Also I Have spring security (through <code>org.springframework.boot:spring-boot-starter-oauth2-client</code> and <code>org.springframework.boot:spring-boot-starter-oauth2-resource-server</code> dependencies). I defined <code>SecurityWebFilterChain</code> as:</p>
  <pre><code>@Bean
      public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
          http
                  .cors().and()
                  .authorizeExchange()
                  .pathMatchers(&quot;/actuator/**&quot;)
                  .permitAll()
                  .and()
                  .authorizeExchange()
                  .anyExchange()
                  .authenticated()
                  .and()
                  .oauth2Login(); // to redirect to oauth2 login page.
  
          return http.build();
      }
  </code></pre>
  <p>When putting build of frontend in static folder there is no CORS error, but for development I need developer node.js server on localhost on different port.</p>
  <p>So, how to fix this cors issue?</p>