package io.reactivesw.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * Created by Davis on 16/12/16.
 */
// TODO: 16/12/16 add for CORS, if somethings wrong, should remove
@Configuration
public class CorsConfiguration {
  /**
   * Cors configurer web mvc configurer.
   *
   * @return the web mvc configurer
   */
  @Bean
  public WebMvcConfigurer corsConfigurer() {
    return new WebMvcConfigurerAdapter() {
      /**
       * add Cors rule.
       * @param registry resigtry
       */
      @Override
      public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
            .allowedHeaders("*")
            .allowedMethods("*")
            .allowedOrigins("*");
      }
    };
  }
}
@@ -31,16 +31,84 @@
 ation;%0A%0A
+import org.springframework.boot.web.servlet.FilterRegistrationBean;%0A
 import o
@@ -212,16 +212,135 @@
 ration;%0A
+import org.springframework.web.cors.UrlBasedCorsConfigurationSource;%0Aimport org.springframework.web.filter.CorsFilter;%0A
 import o
@@ -560,16 +560,42 @@
 apter;%0A%0A
+import java.util.Arrays;%0A%0A
 /**%0A * C
@@ -1238,10 +1238,861 @@
   %7D;%0A  %7D
+%0A%0A  /**%0A   * Cors filter filter registration bean.%0A   * TODO fix cors bug, if somethings wrong, should remove%0A   * @return the filter registration bean%0A   */%0A  @Bean%0A  public FilterRegistrationBean corsFilter()%7B%0A    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();%0A    org.springframework.web.cors.CorsConfiguration config = new org.springframework.web.cors%0A        .CorsConfiguration();%0A    config.setAllowCredentials(true);%0A    config.setAllowedOrigins(Arrays.asList(%22*%22));%0A    config.setAllowedHeaders(Arrays.asList(%22*%22));%0A    config.setAllowedMethods(Arrays.asList(%22*%22));%0A    source.registerCorsConfiguration(%22/**%22, config);%0A    FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new CorsFilter%0A        (source));%0A    filterRegistrationBean.setOrder(0);%0A    return filterRegistrationBean;%0A  %7D
 %0A%7D

fix cors bug