content: package me.aboullaite.config;
  
  
  import org.springframework.boot.web.servlet.FilterRegistrationBean;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.web.cors.CorsConfiguration;
  import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
  import org.springframework.web.filter.CorsFilter;
  import org.springframework.web.servlet.config.annotation.CorsRegistry;
  import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
  
  @Configuration
  public class CorsConfig {
  
  	@Bean
  	public FilterRegistrationBean corsFilter() {
  		UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
  		CorsConfiguration config = new CorsConfiguration();
  		config.setAllowCredentials(true);
  		config.addAllowedOrigin("*");
  		config.addAllowedHeader("*");
  		config.addAllowedMethod("OPTIONS");
  		config.addAllowedMethod("HEAD");
  		config.addAllowedMethod("GET");
  		config.addAllowedMethod("PUT");
  		config.addAllowedMethod("POST");
  		config.addAllowedMethod("DELETE");
  		config.addAllowedMethod("PATCH");
  		source.registerCorsConfiguration("/**", config);
  		// return new CorsFilter(source);
  		final FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
  		bean.setOrder(0);
  		return bean;
  	}
  
  	@Bean
  	public WebMvcConfigurer mvcConfigurer() {
  		return new WebMvcConfigurerAdapter() {
  			public void addCorsMappings(CorsRegistry registry) {
  				registry.addMapping("/**").allowedMethods("GET", "PUT", "POST", "GET", "OPTIONS");
  			}
  		};
  	}
  }
  