You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
초반 빌드가 오래걸릴 수 있지만, 10분이 넘는다면 문제가 있는 상황이 있으니 문제를 빠르게 수정할 수 있도록 하자.
❓문제 개요
CORS 문제 발생
📌 오류 코드 및 오류 메시지
java.lang.IllegalArgumentException: When allowCredentials is true, allowedOrigins cannot contain the special value "*" since that cannot be set on the "Access-Control-Allow-Origin" response header. To allow credentials to a set of origins, list them explicitly or consider using "allowedOriginPatterns" instead.
🔎 원인 분석
서버 배포시 CORS를 생각하지 않고 배포하였다.
📚 해결책
package sopt.jeolloga.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("") // 허용할 도메인 설정
.allowedHeaders("Authorization", "Content-Type")
.exposedHeaders("Custom-Header")
.allowCredentials(true)
.maxAge(3600);
}
}
WebMvcConfigurer 인터페이스를 구현하여 Spring MVC 관련 설정을 커스터마이징 후 addCorsMappings 메서드로 특정 경로에 대한 CORS 정책을 설정
allowedHeaders에 요청에서 전달 가능한 헤더를 설정하고, exposedHeaders에는 클라이언트가 접근 가능한 헤더를 설정
👋 주의 사항
allowCredentials(true)와 allowedOrigins("*") 동시 사용 금지
필요한 OPTIONS 요청을 피하려면 브라우저가 캐시할 수 있는 충분한 maxAge를 설정할 것
웹 배포시에는 CORS 설정을 잊지않고 할수있도록 꼭 기억하기
The text was updated successfully, but these errors were encountered:
❓문제 개요
📌 오류 코드 및 오류 메시지
🔎 원인 분석
📚 해결책
👋 주의 사항
❓문제 개요
📌 오류 코드 및 오류 메시지
🔎 원인 분석
📚 해결책
👋 주의 사항
The text was updated successfully, but these errors were encountered: