본문 바로가기
JW_FREE_NOTE

Cors 설정

by 타블로 2022. 11. 5.
@Configuration
@RequiredArgsConstructor
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        final List<String> httpMethods = Arrays.stream(HttpMethod.values())
                .map(HttpMethod::name)
                .collect(Collectors.toList());

        String[] allowedMethods = new String[httpMethods.size()];

        registry.addMapping("/**")
                .allowedMethods(httpMethods.toArray(allowedMethods))
                .allowedOrigins("*");

    }
}