From e18156dd3e9785883937d9f98f4fa5031b959473 Mon Sep 17 00:00:00 2001 From: Jaeyoung Lim Date: Mon, 3 Jun 2024 08:16:44 +0900 Subject: [PATCH] fix: update CorsConfig --- .../ppoori/global/config/WebConfig.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main/java/dev/goormthon/ppoori/global/config/WebConfig.java b/src/main/java/dev/goormthon/ppoori/global/config/WebConfig.java index 2a992b1..6cb89a8 100644 --- a/src/main/java/dev/goormthon/ppoori/global/config/WebConfig.java +++ b/src/main/java/dev/goormthon/ppoori/global/config/WebConfig.java @@ -1,17 +1,24 @@ package dev.goormthon.ppoori.global.config; +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; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; @Configuration -public class WebConfig implements WebMvcConfigurer { +public class WebConfig { - @Override - public void addCorsMappings(CorsRegistry registry) { - registry.addMapping("/api/**") - .allowedOrigins("https://jejucart-front.vercel.app", "http://localhost:3000", "https://ppoori.shop/api/v1/docs") - .allowedMethods("HEAD", "OPTIONS", "GET", "POST", "PUT", "PATCH", "DELETE") - .allowCredentials(true); + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + CorsConfiguration config = new CorsConfiguration(); + config.setAllowCredentials(true); + config.addAllowedOriginPattern("*"); + config.addAllowedHeader("*"); + config.addAllowedMethod("*"); + + source.registerCorsConfiguration("/api/**", config); + return new CorsFilter(source); } }