commit
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
|
||||||
implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
|
implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
|
||||||
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
|
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
package bit.space.config;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class WebMvcConfig implements WebMvcConfigurer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addCorsMappings(CorsRegistry registry) {
|
|
||||||
registry.addMapping("/**")
|
|
||||||
.allowedOrigins("*")
|
|
||||||
.allowedMethods("OPTIONS", "GET", "POST", "PUT", "DELETE");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package bit.space.config.filter;
|
||||||
|
|
||||||
|
import org.springframework.cloud.gateway.filter.GatewayFilter;
|
||||||
|
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
|
||||||
|
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||||
|
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class GlobalFilter extends AbstractGatewayFilterFactory<GlobalFilter.Config> {
|
||||||
|
|
||||||
|
public GlobalFilter() {
|
||||||
|
super(Config.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GatewayFilter apply(Config config) {
|
||||||
|
|
||||||
|
return ((exchange, chain) -> {
|
||||||
|
ServerHttpRequest request = exchange.getRequest();
|
||||||
|
ServerHttpResponse response = exchange.getResponse();
|
||||||
|
|
||||||
|
log.info("GlobalFilter Message : {}", config.getBaseMessage());
|
||||||
|
|
||||||
|
if(config.isPreLogger()) {
|
||||||
|
log.info("GlobalFilter start : 요청 id -> {}", request.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
return chain.filter(exchange).then(Mono.fromRunnable(()-> {
|
||||||
|
if(config.isPostLogger()) {
|
||||||
|
log.info("GlobalFilter end : 응답 code -> {}", response.getStatusCode());
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class Config {
|
||||||
|
private String baseMessage;
|
||||||
|
private boolean preLogger;
|
||||||
|
private boolean postLogger;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -13,6 +13,30 @@ spring:
|
|||||||
name: gateway-server
|
name: gateway-server
|
||||||
cloud:
|
cloud:
|
||||||
gateway:
|
gateway:
|
||||||
|
globalcors:
|
||||||
|
cors-configurations:
|
||||||
|
'[/**]':
|
||||||
|
allowedOriginPatterns: "*"
|
||||||
|
allow-credentials: true
|
||||||
|
allowedHeaders:
|
||||||
|
- x-requested-with
|
||||||
|
- authorization
|
||||||
|
- content-type
|
||||||
|
- credential
|
||||||
|
- X-AUTH-TOKEN
|
||||||
|
- X-CSRF-TOKEN
|
||||||
|
allowedMethods:
|
||||||
|
- POST
|
||||||
|
- GET
|
||||||
|
- PUT
|
||||||
|
- OPTIONS
|
||||||
|
- DELETE
|
||||||
|
default-filters:
|
||||||
|
- name: GlobalFilter
|
||||||
|
args:
|
||||||
|
baseMessage: GLOBAL FILTER
|
||||||
|
preLogger: true
|
||||||
|
postLogger: true
|
||||||
routes:
|
routes:
|
||||||
- id: member-service
|
- id: member-service
|
||||||
uri: lb://MEMBER-SERVICE
|
uri: lb://MEMBER-SERVICE
|
||||||
|
|||||||
@@ -8,14 +8,14 @@ const App: React.FC = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
mainAxios.get("/member-service/welcome")
|
mainAxios.get("/member-service/welcome")
|
||||||
.then(res => console.log(res))
|
.then(res => setMessage(res.data))
|
||||||
},[])
|
},[])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<img src={logo} className="App-logo" alt="logo" />
|
<img src={logo} className="App-logo" alt="logo" />
|
||||||
<p>
|
<p>
|
||||||
Edit <code>src/App.tsx</code> and save to reload.
|
{message}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user