Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config
19 changes: 6 additions & 13 deletions src/main/java/umc/GrowIT/Server/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
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;

import java.util.List;

@Configuration
public class SwaggerConfig {

@Value("${swagger.server-url}")
private String serverUrl;

@Bean
public OpenAPI GrowITAPI() {
Info info = new Info()
Expand All @@ -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)));
}
}
57 changes: 32 additions & 25 deletions src/main/java/umc/GrowIT/Server/config/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/umc/GrowIT/Server/util/JwtTokenUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down