Skip to content

Commit

Permalink
[Bug] :: swagger cors error fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lgwk42 committed May 23, 2024
1 parent aeaa191 commit acd6242
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
public class CheckCodeExpirationException extends BusinessException {

public static final CheckCodeExpirationException EXCEPTION = new CheckCodeExpirationException();

private CheckCodeExpirationException(){
super(CheckError.CHECK_CODE_EXPIRATION);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*") // 필요한 출처를 명시
.allowedOriginPatterns("*") // 필요한 출처를 명시
.allowedMethods("*")
.allowedHeaders("*")
.allowCredentials(true)
Expand All @@ -24,12 +24,13 @@ public WebMvcConfigurer corsConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedOriginPatterns("*")
.allowedMethods("*")
.allowedHeaders("*")
.allowCredentials(true)
.maxAge(3600);
}
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
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 static org.springframework.http.HttpMethod.DELETE;
import static org.springframework.http.HttpMethod.GET;
import static org.springframework.http.HttpMethod.PATCH;
import static org.springframework.http.HttpMethod.POST;
import static org.springframework.http.HttpMethod.*;

@Configuration
@EnableWebSecurity
Expand Down Expand Up @@ -77,4 +76,16 @@ public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}

@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.addAllowedOriginPattern("*");
configuration.addAllowedHeader("*");
configuration.addAllowedMethod("*");
configuration.setAllowCredentials(true);
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}

}

0 comments on commit acd6242

Please sign in to comment.