-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 기존 WebMvcConfigurer 방식에서 CorsConfigurationSource 로 변경합니다. - http://192.168.0.* 에서 오는 요청에 대해 모두 허용합니다.
- Loading branch information
1 parent
98d02d1
commit 7ba3796
Showing
1 changed file
with
17 additions
and
15 deletions.
There are no files selected for viewing
32 changes: 17 additions & 15 deletions
32
src/main/java/goorm/reinput/global/security/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 |
---|---|---|
@@ -1,24 +1,26 @@ | ||
package goorm.reinput.global.security; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
import org.springframework.web.cors.CorsConfiguration; | ||
import org.springframework.web.cors.CorsConfigurationSource; | ||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource; | ||
import org.springframework.web.util.pattern.PathPatternParser; | ||
import java.util.Arrays; | ||
|
||
@Configuration | ||
public class CorsConfig implements WebMvcConfigurer { | ||
public class CorsConfig { | ||
|
||
// TODO: cors 설정. dev, prod 주소 추가 예정 | ||
// @Value("${cors.origin.development}") | ||
// private String developmentOrigin; | ||
// | ||
// @Value("${cors.origin.production}") | ||
// private String productionOrigin; | ||
@Bean | ||
public CorsConfigurationSource corsConfigurationSource() { | ||
CorsConfiguration config = new CorsConfiguration(); | ||
config.setAllowedOriginPatterns(Arrays.asList("http://192.168.0.*")); | ||
config.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD")); | ||
config.setAllowedHeaders(Arrays.asList("Authorization", "Cache-Control", "Content-Type")); | ||
config.setAllowCredentials(true); | ||
|
||
@Override | ||
public void addCorsMappings(CorsRegistry registry) { | ||
registry.addMapping("/**") | ||
.allowedMethods("OPTIONS", "HEAD", "GET", "POST", "PUT", "PATCH", "DELETE") | ||
.allowCredentials(true) | ||
.allowedOrigins("http://localhost:3000","https://2024-beotkkotthon-team-24-fe.vercel.app", "https://reinput.info", "https://www.reinput.info"); | ||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser()); | ||
source.registerCorsConfiguration("/**", config); | ||
return source; | ||
} | ||
} |