fix(backend): fixed cors error on build dev environment
This commit is contained in:
parent
78c3292dd9
commit
022f8e40ba
1 changed files with 3 additions and 3 deletions
|
|
@ -44,7 +44,7 @@ public class SecurityConfig {
|
||||||
private String jwtSecret;
|
private String jwtSecret;
|
||||||
|
|
||||||
@Value("${app.cors-origins:http://localhost:4200}")
|
@Value("${app.cors-origins:http://localhost:4200}")
|
||||||
private String corsOrigins;
|
private List<String> corsOrigins;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public JwtDecoder jwtDecoder() {
|
public JwtDecoder jwtDecoder() {
|
||||||
|
|
@ -95,7 +95,7 @@ public class SecurityConfig {
|
||||||
@Bean
|
@Bean
|
||||||
public CorsConfigurationSource corsConfigurationSource() {
|
public CorsConfigurationSource corsConfigurationSource() {
|
||||||
CorsConfiguration configuration = new CorsConfiguration();
|
CorsConfiguration configuration = new CorsConfiguration();
|
||||||
List<String> allowedPatterns = Arrays.stream(corsOrigins.split(","))
|
List<String> allowedPatterns = corsOrigins.stream()
|
||||||
.map(String::trim)
|
.map(String::trim)
|
||||||
.flatMap(origin -> {
|
.flatMap(origin -> {
|
||||||
if (origin.contains("*")) {
|
if (origin.contains("*")) {
|
||||||
|
|
@ -111,7 +111,7 @@ public class SecurityConfig {
|
||||||
configuration.setAllowCredentials(true);
|
configuration.setAllowCredentials(true);
|
||||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||||
source.registerCorsConfiguration("/**", configuration);
|
source.registerCorsConfiguration("/**", configuration);
|
||||||
System.out.println("LOGGED CORS ORIGINS: " + corsOrigins);
|
System.out.println("LOGGED CORS ORIGINS: " + String.join(",", corsOrigins));
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue