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;
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("http://localhost:3000") // 통신할 서버 URL(프론트엔드 등)
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.allowCredentials(true);
}
}
1) XMLHttpRequest, FetchAPI는 기본적으로 Same-Origin 정책을 따름
(다른 도메인 소스에 대해 ajax 요청 API호출시)
2) SOR은 서버에 있는 리소스는 자유롭게 가져올 수다
1) < img > , < video >, < script >, < link >등은 기본적으로 Cross-Origin 정책을 지원
2) CORS는 서버에 있는 이미지나 유튜브 영상 같은 리소스는 상호작용이 불가능