Skip to content

Commit

Permalink
Refactor : cors 설정 yml로 관리하도록 변경 (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
Astin01 authored Oct 20, 2024
1 parent 5786bff commit f18daf9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,6 +17,10 @@
@Configuration
public class AuthConfiguration implements WebMvcConfigurer {


@Autowired
private CorsProperties corsProperties;

private final JwtTokenProvider jwtTokenProvider;
private final TokenRepository tokenRepository;

Expand All @@ -40,16 +46,10 @@ public void addArgumentResolvers(List<HandlerMethodArgumentResolver> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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<String> allowedOrigins;
private List<String> allowedMethods;
private List<String> allowedHeaders;
}

0 comments on commit f18daf9

Please sign in to comment.