728x90
[ 상황 ]
Vue 에서 axios 로 File 객체를 전송하려는 중 마주한 에러
GET 요청은 CORS 에러없이 쓰고 있었는데 POST 요청시 발생하였던 것이 주요 문제다.
[ 에러 ]
"when allowCridencial is ture, allowedOrigins cannot contain the special value "*" sins that cannot be set on the "Acess-Control-Allow-Origin ~ "
-> allowCredentials 가 true 일 때는 allowedOrigins("*") 로 설정하면 안된다는 문구 !
[ 문제 ]
CORS 표준에 따라 "allowCredentials(true)" 와 "allowedOrigins("*")" 를 같이 쓸수 없기 때문에 발생
[ 해결 ]
1. SpringBoot 3.x 이상에서는 "allowedOrigins("*")" 대신 "allowedOriginPatterns("*") 를 사용한다.
2. 구체적인 도메인을 작성한다
ex) "*" 대신 특적 origin 지정 - "http://localhost:5173" 등
나는 1번을 통해 해결했음 !
728x90
'Backend > Spring & Spring Boot' 카테고리의 다른 글
| FeignClient - Spring Cloud 에서 제공하는 HTTP 클라이언트 (2) | 2025.07.10 |
|---|---|
| 스프링 롬복 인식 실패 문제 해결 (4) | 2025.06.16 |
| @RequiredArgsConstructor 의 역할 ( 생성자 주입 vs 필드 주입 ) (1) | 2025.06.05 |
| Spring Security - SimpleGrantedAuthority, UserDetails, UserDetailsService (0) | 2025.05.29 |
| Spring Security 의 초기 username 설정 위치 (0) | 2025.04.29 |