Skip to content

Instantly share code, notes, and snippets.

@unclebean
Created September 16, 2024 04:43
Show Gist options
  • Save unclebean/9eef9b2330412ece5ac438922d536936 to your computer and use it in GitHub Desktop.
Save unclebean/9eef9b2330412ece5ac438922d536936 to your computer and use it in GitHub Desktop.
Cora
@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(List.of("*")); // Allow all origins, or specify specific ones
configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS")); // Allow all methods
configuration.setAllowedHeaders(List.of("*")); // Allow all headers
configuration.setAllowCredentials(true); // Allow credentials like cookies
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration); // Apply CORS config to all endpoints
return source;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment