Skip to content

Commit

Permalink
fix cors
Browse files Browse the repository at this point in the history
  • Loading branch information
SachaWildCode committed Jul 30, 2024
1 parent 8ab3aa3 commit 90414b8
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/main/java/fr/slghive/heartlink/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.servlet.HandlerExceptionResolver;

@Configuration
Expand Down Expand Up @@ -81,14 +82,15 @@ public PasswordEncoder passwordEncoder() {

@Bean
public CorsConfigurationSource corsConfigurationSource() {
return req -> {
CorsConfiguration cors = new CorsConfiguration();
cors.setAllowedOrigins(List.of("https://heartlink.slghive.fr"));
cors.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS"));
cors.setAllowedHeaders(List.of("Authorization", "Cache-Control", "Content-Type"));
cors.setAllowCredentials(true);
cors.setMaxAge(3600L);
return cors;
};
CorsConfiguration corsConfig = new CorsConfiguration();
corsConfig.setAllowedOrigins(List.of("https://heartlink.slghive.fr")); // Set allowed origins
corsConfig.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS")); // Set allowed methods
corsConfig.setAllowedHeaders(List.of("Authorization", "Cache-Control", "Content-Type")); // Set allowed headers
corsConfig.setAllowCredentials(true);
corsConfig.setMaxAge(3600L); // Set max age for preflight requests
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", corsConfig); // Register CORS configuration for all paths

return source;
}
}

0 comments on commit 90414b8

Please sign in to comment.