Skip to content

Commit

Permalink
✨ [feat] CORS 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
rimi3226 committed Jul 16, 2024
1 parent 2a0fb52 commit 2a9888e
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/main/java/com/gamegoo/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

import java.util.Arrays;
import java.util.List;

import static org.springframework.security.config.Customizer.withDefaults;

@Configuration
@EnableWebSecurity
@RequiredArgsConstructor
Expand Down Expand Up @@ -55,7 +60,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.csrf(AbstractHttpConfigurer::disable)
.formLogin(AbstractHttpConfigurer::disable)
.httpBasic(AbstractHttpConfigurer::disable)

.cors(withDefaults())
.authorizeHttpRequests((auth) -> auth
.antMatchers("/", "/api/member/join", "/api/member/login", "/api/member/email/**", "/api/member/refresh", "/api/member/riot").permitAll()

Expand All @@ -69,4 +74,16 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {

return http.build();
}

@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin("http://localhost:3000");
config.addAllowedHeader("*");
config.addAllowedMethod("*");
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}
}

0 comments on commit 2a9888e

Please sign in to comment.