Skip to content

Commit

Permalink
Bug: Cors 오류 테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
nampongo committed Mar 15, 2024
1 parent c4d3b2e commit eacd6d0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/senity/waved/base/config/CorsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

@Configuration
public class CorsConfig {

@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
Expand All @@ -18,7 +19,6 @@ public CorsFilter corsFilter() {
config.addAllowedMethod("*");

source.registerCorsConfiguration("/**", config);

return new CorsFilter(source);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
import org.springframework.security.web.access.intercept.FilterSecurityInterceptor;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@EnableWebSecurity
@RequiredArgsConstructor
public class WebSecurityConfig {
public class WebSecurityConfig implements WebMvcConfigurer {
private final TokenProvider tokenProvider;
private final CorsFilter corsFilter;
private final CustomOAuth2UserService customOAuth2UserService;
Expand Down Expand Up @@ -57,4 +59,13 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti

return http.build();
}

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("https://localhost:3000") // 허용할 도메인을 지정합니다
.allowedMethods("GET", "POST", "PUT", "DELETE") // 허용할 HTTP 메서드를 지정합니다
.allowedHeaders("*") // 허용할 요청 헤더를 지정합니다
.allowCredentials(true); // 인증 정보를 포함할지 여부를 지정합니다
}
}
1 change: 1 addition & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ spring:
registration:
google:
client-name: Google
redirect-uri: http://localhost:3000/oauth
scope:
- email
- profile
Expand Down

0 comments on commit eacd6d0

Please sign in to comment.