Skip to content

Instantly share code, notes, and snippets.

@timjonesdev
Created August 21, 2019 17:21
Show Gist options
  • Select an option

  • Save timjonesdev/de2d8feb477954eeffb5765bf0ec714a to your computer and use it in GitHub Desktop.

Select an option

Save timjonesdev/de2d8feb477954eeffb5765bf0ec714a to your computer and use it in GitHub Desktop.
A simple CORS filter
@Bean
CorsWebFilter corsFilter() {
CorsConfiguration config = new CorsConfiguration();
// Possibly...
// config.applyPermitDefaultValues()
config.setAllowCredentials(true);
// allow access to my dev Angular instance
config.addAllowedOrigin("http://localhost:4200");
config.addAllowedHeader("*");
config.addAllowedMethod("*");
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", config);
return new CorsWebFilter(source);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment