feat : initial commit
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'org.springframework.boot' version '3.4.0'
|
||||
id 'io.spring.dependency-management' version '1.1.4'
|
||||
}
|
||||
|
||||
group = 'com.healthsync'
|
||||
version = '1.0.0'
|
||||
|
||||
java {
|
||||
sourceCompatibility = '17'
|
||||
}
|
||||
|
||||
configurations {
|
||||
compileOnly {
|
||||
extendsFrom annotationProcessor
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation project(':common')
|
||||
implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
|
||||
implementation 'org.springframework.cloud:spring-cloud-starter-loadbalancer'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-actuator'
|
||||
implementation 'org.springdoc:springdoc-openapi-starter-webflux-ui:2.7.0'
|
||||
|
||||
compileOnly 'org.projectlombok:lombok'
|
||||
annotationProcessor 'org.projectlombok:lombok'
|
||||
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
}
|
||||
|
||||
dependencyManagement {
|
||||
imports {
|
||||
mavenBom 'org.springframework.cloud:spring-cloud-dependencies:2023.0.0'
|
||||
}
|
||||
}
|
||||
|
||||
tasks.named('test') {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.healthsync.gateway;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* API Gateway의 메인 애플리케이션 클래스입니다.
|
||||
* 모든 서비스로의 요청을 라우팅하는 역할을 담당합니다.
|
||||
*
|
||||
* @author healthsync-team
|
||||
* @version 1.0
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class GatewayApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(GatewayApplication.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.healthsync.gateway.config;
|
||||
|
||||
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* Gateway 설정을 관리하는 클래스입니다.
|
||||
*
|
||||
* @author healthsync-team
|
||||
* @version 1.0
|
||||
*/
|
||||
@Configuration
|
||||
public class GatewayConfig {
|
||||
|
||||
/**
|
||||
* 요청/응답 로깅을 위한 글로벌 필터를 설정합니다.
|
||||
*
|
||||
* @return 로깅 글로벌 필터
|
||||
*/
|
||||
@Bean
|
||||
@Order(-1)
|
||||
public GlobalFilter loggingFilter() {
|
||||
return (exchange, chain) -> {
|
||||
String requestPath = exchange.getRequest().getPath().value();
|
||||
String requestMethod = exchange.getRequest().getMethod().name();
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
return chain.filter(exchange).then(
|
||||
Mono.fromRunnable(() -> {
|
||||
long endTime = System.currentTimeMillis();
|
||||
long duration = endTime - startTime;
|
||||
|
||||
System.out.printf("Gateway: %s %s - %dms%n",
|
||||
requestMethod, requestPath, duration);
|
||||
})
|
||||
);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
spring:
|
||||
application:
|
||||
name: api-gateway
|
||||
security :
|
||||
enabled: false
|
||||
|
||||
# Gateway는 Reactive 웹 애플리케이션으로 설정
|
||||
main:
|
||||
web-application-type: reactive
|
||||
|
||||
autoconfigure:
|
||||
exclude:
|
||||
- org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
|
||||
- org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration
|
||||
- org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration
|
||||
- org.springframework.boot.autoconfigure.data.redis.RedisReactiveAutoConfiguration
|
||||
# 보안 관련 모든 자동 설정 제외
|
||||
- org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration
|
||||
- org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration
|
||||
- org.springframework.boot.autoconfigure.security.reactive.ReactiveSecurityAutoConfiguration
|
||||
- org.springframework.boot.autoconfigure.security.reactive.ReactiveUserDetailsServiceAutoConfiguration
|
||||
# Actuator 보안 자동 설정 제외 추가
|
||||
- org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration
|
||||
- org.springframework.boot.actuate.autoconfigure.security.reactive.ReactiveManagementWebSecurityAutoConfiguration
|
||||
|
||||
# Spring Cloud 설정 (통합)
|
||||
cloud:
|
||||
# 호환성 체크 비활성화
|
||||
compatibility-verifier:
|
||||
enabled: false
|
||||
|
||||
# Gateway 설정
|
||||
gateway:
|
||||
routes:
|
||||
# User Service 라우팅
|
||||
- id: user-service
|
||||
uri: ${USER_SERVICE_URL:http://localhost:8081}
|
||||
predicates:
|
||||
- Path=/api/auth/**, /api/user/**, /login/oauth2/code/**, /oauth2/authorization/**
|
||||
filters:
|
||||
- RewritePath=/api/(?!oauth2)(?<segment>.*), /${segment}
|
||||
|
||||
# Health Service 라우팅
|
||||
- id: health-service
|
||||
uri: ${HEALTH_SERVICE_URL:http://localhost:8082}
|
||||
predicates:
|
||||
- Path=/api/health/**
|
||||
filters:
|
||||
- RewritePath=/api/(?<segment>.*), /$\{segment}
|
||||
|
||||
# Intelligence Service 라우팅
|
||||
- id: intelligence-service
|
||||
uri: ${INTELLIGENCE_SERVICE_URL:http://localhost:8083}
|
||||
predicates:
|
||||
- Path=/api/intelligence/**
|
||||
filters:
|
||||
- RewritePath=/api/(?<segment>.*), /$\{segment}
|
||||
|
||||
# Goal Service 라우팅
|
||||
- id: goal-service
|
||||
uri: ${GOAL_SERVICE_URL:http://localhost:8084}
|
||||
predicates:
|
||||
- Path=/api/goals/**
|
||||
filters:
|
||||
- RewritePath=/api/(?<segment>.*), /$\{segment}
|
||||
|
||||
# Motivator Service 라우팅
|
||||
- id: motivator-service
|
||||
uri: ${MOTIVATOR_SERVICE_URL:http://localhost:8085}
|
||||
predicates:
|
||||
- Path=/api/motivator/**
|
||||
filters:
|
||||
- RewritePath=/api/(?<segment>.*), /$\{segment}
|
||||
|
||||
# CORS 설정
|
||||
globalcors:
|
||||
cors-configurations:
|
||||
'[/**]':
|
||||
allowedOriginPatterns: "*"
|
||||
allowedMethods:
|
||||
- GET
|
||||
- POST
|
||||
- PUT
|
||||
- DELETE
|
||||
- OPTIONS
|
||||
allowedHeaders: "*"
|
||||
allowCredentials: true
|
||||
|
||||
default-filters:
|
||||
- DedupeResponseHeader=Access-Control-Allow-Credentials Access-Control-Allow-Origin
|
||||
|
||||
# 서버 포트 설정
|
||||
server:
|
||||
port: ${SERVER_PORT:8080}
|
||||
|
||||
# 모니터링 엔드포인트
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: health,info
|
||||
endpoint:
|
||||
health:
|
||||
show-details: always
|
||||
|
||||
# 로깅 설정
|
||||
logging:
|
||||
level:
|
||||
org.springframework.cloud.gateway: ${GATEWAY_LOG_LEVEL:TRACE}
|
||||
reactor.netty: ${NETTY_LOG_LEVEL:TRACE}
|
||||
reactor.netty.http.client: TRACE
|
||||
reactor.netty.http.server: TRACE
|
||||
org.apache.http: TRACE
|
||||
org.apache.http.wire: TRACE # HTTP 와이어 레벨 로깅 (실제 HTTP 메시지)
|
||||
pattern:
|
||||
console: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n"
|
||||
Reference in New Issue
Block a user