- vue에서 spring data를 받아오려면 별도의 설정을 해주어야 한다.
package com.nineties.bhr.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("http://localhost:3000") // 허용할 오리진
.allowedMethods("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS") // 허용할 HTTP 메소드
.allowedHeaders("*") // 허용할 헤더
.allowCredentials(true) // 쿠키를 넘기는 요청을 허용할지 여부
.maxAge(3600); // pre-flight 요청의 캐시 지속 시간(초 단위)
}
}