diff --git a/config b/config index 77b78fbf..ef8d0d30 160000 --- a/config +++ b/config @@ -1 +1 @@ -Subproject commit 77b78fbf2a79cc6031550e11e0b2928f26ff0774 +Subproject commit ef8d0d30f766afa062a666d6263d0544c006e9f9 diff --git a/src/main/java/umc/GrowIT/Server/config/SwaggerConfig.java b/src/main/java/umc/GrowIT/Server/config/SwaggerConfig.java index 7e563e2a..2abf1abc 100644 --- a/src/main/java/umc/GrowIT/Server/config/SwaggerConfig.java +++ b/src/main/java/umc/GrowIT/Server/config/SwaggerConfig.java @@ -6,6 +6,7 @@ import io.swagger.v3.oas.models.security.SecurityRequirement; import io.swagger.v3.oas.models.security.SecurityScheme; import io.swagger.v3.oas.models.servers.Server; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -13,6 +14,10 @@ @Configuration public class SwaggerConfig { + + @Value("${swagger.server-url}") + private String serverUrl; + @Bean public OpenAPI GrowITAPI() { Info info = new Info() @@ -32,23 +37,11 @@ public OpenAPI GrowITAPI() { .scheme("bearer") .bearerFormat("JWT")); - // 여러 서버 환경 설정 - Server localServer = new Server() - .url("http://localhost:8080") - .description("local"); - - Server devServer = new Server() - .url("https://dev.growitserver.shop") - .description("dev"); - - Server prodServer = new Server() - .url("https://growitserver.shop") - .description("prod"); return new OpenAPI() .info(info) .addSecurityItem(securityRequirement) .components(components) - .servers(List.of(localServer, devServer, prodServer)); + .servers(List.of(new Server().url(serverUrl))); } } diff --git a/src/main/java/umc/GrowIT/Server/config/WebConfig.java b/src/main/java/umc/GrowIT/Server/config/WebConfig.java index 5865c3d7..d4f63237 100644 --- a/src/main/java/umc/GrowIT/Server/config/WebConfig.java +++ b/src/main/java/umc/GrowIT/Server/config/WebConfig.java @@ -2,6 +2,7 @@ import java.util.List; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.cors.CorsConfiguration; @@ -12,36 +13,42 @@ @Configuration public class WebConfig implements WebMvcConfigurer { + @Value("${cors.allowed-origins}") + private String allowedOrigins; + @Bean public CorsConfigurationSource corsConfigurationSource() { CorsConfiguration config = new CorsConfiguration(); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); - // 허용할 origin 설정 (Swagger UI 웹 테스트용) - config.setAllowedOriginPatterns(List.of( - "http://localhost:8080", - "https://dev.growitserver.shop" - )); - - // 허용할 HTTP 메서드 - config.setAllowedMethods(List.of( - "GET", - "POST", - "DELETE", - "PATCH" - )); - - // 허용할 헤더 - config.setAllowedHeaders(List.of( - "Authorization", - "Content-Type" - )); - - // 인증 정보 허용 - config.setAllowCredentials(true); - - // 모든 경로에 적용 - source.registerCorsConfiguration("/**", config); + if (!allowedOrigins.isEmpty()) { + // 허용할 origin 설정 (Swagger UI 웹 테스트용) + config.setAllowedOriginPatterns(List.of( + "http://localhost:8080", + "https://dev.growitserver.shop", + "https://growitserver.shop" + )); + + // 허용할 HTTP 메서드 + config.setAllowedMethods(List.of( + "GET", + "POST", + "DELETE", + "PATCH" + )); + + // 허용할 헤더 + config.setAllowedHeaders(List.of( + "Authorization", + "Content-Type" + )); + + // 인증 정보 허용 + config.setAllowCredentials(true); + + // 모든 경로에 적용 + source.registerCorsConfiguration("/**", config); + } return source; } diff --git a/src/main/java/umc/GrowIT/Server/util/JwtTokenUtil.java b/src/main/java/umc/GrowIT/Server/util/JwtTokenUtil.java index 046b7110..9f436f18 100644 --- a/src/main/java/umc/GrowIT/Server/util/JwtTokenUtil.java +++ b/src/main/java/umc/GrowIT/Server/util/JwtTokenUtil.java @@ -37,7 +37,7 @@ public class JwtTokenUtil { @Value("${jwt.refresh-token-expiration-ms}") private long REFRESH_TOKEN_EXPIRATION_MS; - public JwtTokenUtil(@Value("${spring.jwt.secretKey}") String secretKey, UserQueryService userQueryService) { + public JwtTokenUtil(@Value("${jwt.secretKey}") String secretKey, UserQueryService userQueryService) { byte[] keyBytes = Decoders.BASE64.decode(secretKey); this.key = Keys.hmacShaKeyFor(keyBytes); this.userQueryService = userQueryService;