Skip to content

Instantly share code, notes, and snippets.

@finsterthecat
Last active January 8, 2018 23:26
Show Gist options
  • Save finsterthecat/d56c5047f05cb47a101d022c729d2034 to your computer and use it in GitHub Desktop.
Save finsterthecat/d56c5047f05cb47a101d022c729d2034 to your computer and use it in GitHub Desktop.
package io.navan.heroesbackend;
import java.util.Arrays;
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;
@Configuration
public class CorsConfig {
@Bean
public CorsFilter corsFilter() {
CorsConfiguration config = new CorsConfiguration();
config.addAllowedOrigin("*");
config.addAllowedHeader("*");
config.setAllowedMethods(Arrays.asList(
new String[] {"OPTIONS", "GET", "POST", "PUT", "DELETE"}));
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment