-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/com/capic/server/global/config/CorsConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.capic.server.global.config; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
import org.springframework.web.cors.CorsConfiguration; | ||
import org.springframework.web.cors.CorsConfigurationSource; | ||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource; | ||
|
||
import java.util.List; | ||
@Configuration | ||
@EnableWebSecurity | ||
@RequiredArgsConstructor | ||
public class CorsConfig { | ||
/** | ||
* CORS 허용하도록 커스터마이징 진행 | ||
* @return - 변경된 CORS 정책 정보 반환 | ||
*/ | ||
@Bean | ||
CorsConfigurationSource corsConfigurationSource() { | ||
CorsConfiguration config = new CorsConfiguration(); | ||
|
||
// 인증정보 주고받도록 허용 | ||
config.setAllowCredentials(true); | ||
// 허용할 주소 | ||
config.setAllowedOriginPatterns(List.of("*")); | ||
// 허용할 HTTP Method | ||
config.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS")); | ||
// 허용할 헤더 정보 | ||
config.setAllowedHeaders(List.of("*")); | ||
config.setExposedHeaders(List.of("*")); | ||
|
||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); | ||
source.registerCorsConfiguration("/**", config); | ||
|
||
return source; | ||
} | ||
|
||
} |