diff --git a/src/main/java/solitour_backend/solitour/auth/config/AuthConfiguration.java b/src/main/java/solitour_backend/solitour/auth/config/AuthConfiguration.java index f522392..d003ccc 100644 --- a/src/main/java/solitour_backend/solitour/auth/config/AuthConfiguration.java +++ b/src/main/java/solitour_backend/solitour/auth/config/AuthConfiguration.java @@ -2,6 +2,8 @@ import java.util.List; import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.servlet.config.annotation.CorsRegistry; @@ -15,6 +17,10 @@ @Configuration public class AuthConfiguration implements WebMvcConfigurer { + + @Autowired + private CorsProperties corsProperties; + private final JwtTokenProvider jwtTokenProvider; private final TokenRepository tokenRepository; @@ -40,16 +46,10 @@ public void addArgumentResolvers(List resolvers) @Override public void addCorsMappings(CorsRegistry registry) { - final String[] ALLOWED_URLS = { - "http://localhost:3000", - "https://solitour.ssssksss.xyz", - "https://solitour-admin.ssssksss.xyz" - }; - registry.addMapping("/**") - .allowedOrigins(ALLOWED_URLS) - .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") - .allowedHeaders("*") + .allowedOrigins(corsProperties.getAllowedOrigins().toArray(new String[0])) + .allowedMethods(corsProperties.getAllowedMethods().toArray(new String[0])) + .allowedHeaders(corsProperties.getAllowedHeaders().toArray(new String[0])) .allowCredentials(true); } } diff --git a/src/main/java/solitour_backend/solitour/auth/config/CorsProperties.java b/src/main/java/solitour_backend/solitour/auth/config/CorsProperties.java new file mode 100644 index 0000000..e29c3a9 --- /dev/null +++ b/src/main/java/solitour_backend/solitour/auth/config/CorsProperties.java @@ -0,0 +1,20 @@ +package solitour_backend.solitour.auth.config; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import java.util.List; + + +@Component +@Getter +@Setter +@ConfigurationProperties(prefix = "cors") +public class CorsProperties { + private List allowedOrigins; + private List allowedMethods; + private List allowedHeaders; +}