fix: SpringDocsConfig 서버 목록 추가

- http, https 서버
     Cors yml 설정 정리
dev
gitea-관리자 12 months ago
parent f9d0f67175
commit 6734c05949

@ -47,10 +47,6 @@ logging:
path: ${app.data.root.path}/mens/logs path: ${app.data.root.path}/mens/logs
name: ${app.name} name: ${app.name}
# Spring Security cors 설정 :: CorsConfiguration 설정 값
cors:
allowed-origins: http://localhost:8080, http://${app.api-ip}:8080, http://localhost:8082, http://${app.api-ip}:8082
# ================================================================================================================== # ==================================================================================================================
# SQL logging lib setting # SQL logging lib setting
# ================================================================================================================== # ==================================================================================================================
@ -65,7 +61,11 @@ app:
#swagger-url: 'http://localhost:${server.port}${server.servlet.context-path:}/' #swagger-url: 'http://localhost:${server.port}${server.servlet.context-path:}/'
# Spring Security cors 설정 :: CorsConfiguration 설정 값 # Spring Security cors 설정 :: CorsConfiguration 설정 값
cors: cors:
allowed-origins: http://localhost:8080, http://${app.api-ip}:8080, http://localhost:8082, http://${app.api-ip}:8082 allowed-origins:
http://localhost:${server.http},
http://${app.api-ip}:${server.http},
https://localhost:${server.port},
https://${app.api-ip}:${server.port}
data: data:
root: root:

@ -44,10 +44,6 @@ logging:
path: ${app.data.root.path}/mens/logs path: ${app.data.root.path}/mens/logs
name: ${app.name} name: ${app.name}
# Spring Security cors 설정 :: CorsConfiguration 설정 값
cors:
allowed-origins: http://localhost:8080, http://${app.api-ip}:8080, http://localhost:8082, http://${app.api-ip}:8082
# ================================================================================================================== # ==================================================================================================================
# SQL logging lib setting # SQL logging lib setting
# ================================================================================================================== # ==================================================================================================================

@ -56,10 +56,6 @@ logging:
path: ${app.data.root.path}/mens/logs path: ${app.data.root.path}/mens/logs
name: ${app.name} name: ${app.name}
# Spring Security cors 설정 :: CorsConfiguration 설정 값
cors:
allowed-origins: http://localhost:8080
# ================================================================================================================== # ==================================================================================================================
# SQL logging lib setting # SQL logging lib setting
# ================================================================================================================== # ==================================================================================================================

@ -7,6 +7,7 @@ import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement; import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme; import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.servers.Server; import io.swagger.v3.oas.models.servers.Server;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import kr.xit.core.support.utils.Checks; import kr.xit.core.support.utils.Checks;
@ -36,7 +37,7 @@ import org.springframework.context.annotation.Configuration;
@Configuration @Configuration
public class SpringDocsConfig { public class SpringDocsConfig {
@Value("${server.port}") @Value("${server.port}")
private int SSL_PORT; private int SERVER_PORT;
@Value("${server.http:0}") @Value("${server.http:0}")
private int HTTP_PORT; private int HTTP_PORT;
@Value("${app.swagger-url:}") @Value("${app.swagger-url:}")
@ -58,8 +59,17 @@ public class SpringDocsConfig {
.email("admin@xit.co.kr")); .email("admin@xit.co.kr"));
//.url("http://www.xerotech.co.kr/")); //.url("http://www.xerotech.co.kr/"));
String url = Checks.isNotEmpty(swaggerUrl)? swaggerUrl : String.format("http://localhost:%d", HTTP_PORT != 0? HTTP_PORT: SSL_PORT); // https enabled
List<Server> servers = Collections.singletonList(new Server().url(url).description(name + "(" + active + ")")); List<Server> servers = new ArrayList<>();
if(HTTP_PORT != 0){
String httpsUrl = Checks.isNotEmpty(swaggerUrl)? swaggerUrl : String.format("https://localhost:%d", SERVER_PORT);
String httpUrl = Checks.isNotEmpty(swaggerUrl)? swaggerUrl : String.format("http://localhost:%d", HTTP_PORT);
servers.add(new Server().url(httpsUrl).description(name + "(" + active + ")"));
servers.add(new Server().url(httpUrl).description(name + "(" + active + ")"));
}else {
String httpUrl = Checks.isNotEmpty(swaggerUrl)? swaggerUrl : String.format("http://localhost:%d", SERVER_PORT);
servers.add(new Server().url(httpUrl).description(name + "(" + active + ")"));
}
// Security 스키마 설정 // Security 스키마 설정
SecurityScheme securityScheme = new SecurityScheme() SecurityScheme securityScheme = new SecurityScheme()
@ -69,11 +79,13 @@ public class SpringDocsConfig {
.in(SecurityScheme.In.HEADER) .in(SecurityScheme.In.HEADER)
// .name(HttpHeaders.AUTHORIZATION); // .name(HttpHeaders.AUTHORIZATION);
.name("Authorization"); .name("Authorization");
SecurityRequirement securityRequirement = new SecurityRequirement().addList("bearerAuth"); SecurityRequirement securityRequirement = new SecurityRequirement().addList("bearerAuth");
return new OpenAPI() return new OpenAPI()
// Security 인증 컴포넌트 설정 // Security 인증 컴포넌트 설정
.components(new Components().addSecuritySchemes("bearerAuth", securityScheme)) .components(new Components().addSecuritySchemes("bearerAuth", securityScheme))
.components(new Components().addSecuritySchemes("bearerAuth", securityScheme))
// API 마다 Security 인증 컴포넌트 설정 // API 마다 Security 인증 컴포넌트 설정
//.addSecurityItem(new SecurityRequirement().addList("JWT")) //.addSecurityItem(new SecurityRequirement().addList("JWT"))
.security(Collections.singletonList(securityRequirement)) .security(Collections.singletonList(securityRequirement))

Loading…
Cancel
Save