|
@@ -1,60 +0,0 @@
|
|
-package com.caimei365.user.config;
|
|
|
|
-
|
|
|
|
-import org.springframework.context.annotation.Configuration;
|
|
|
|
-import org.springframework.http.server.reactive.ServerHttpRequest;
|
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
|
-import org.springframework.web.reactive.config.WebFluxConfigurer;
|
|
|
|
-import org.springframework.web.server.ServerWebExchange;
|
|
|
|
-import org.springframework.web.server.WebFilter;
|
|
|
|
-import org.springframework.web.server.WebFilterChain;
|
|
|
|
-import reactor.core.publisher.Mono;
|
|
|
|
-
|
|
|
|
-import java.net.InetSocketAddress;
|
|
|
|
-import java.util.Objects;
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * Description
|
|
|
|
- *
|
|
|
|
- * @author : Charles
|
|
|
|
- * @date : 2021/3/11
|
|
|
|
- */
|
|
|
|
-//@Configuration
|
|
|
|
-//public class WebConfiguration implements WebFluxConfigurer {
|
|
|
|
-//
|
|
|
|
-// /**
|
|
|
|
-// * https://stackoverflow.com/questions/51192630/how-do-you-get-clients-ip-address-spring-webflux-websocket?rq=1
|
|
|
|
-// * https://stackoverflow.com/questions/50981136/how-to-get-client-ip-in-webflux
|
|
|
|
-// * https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html#webflux-filters
|
|
|
|
-// * 由于在低版本的 spring-webflux 中不支持直接获得请求 IP(https://jira.spring.io/browse/SPR-16681),
|
|
|
|
-// * 因此从org.springframework.web.server.ServerWebExchange中获得 IP 后,在放到 header 里
|
|
|
|
-// */
|
|
|
|
-// @Component
|
|
|
|
-// public static class RetrieveClientIpWebFilter implements WebFilter {
|
|
|
|
-// @Override
|
|
|
|
-// public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
|
|
|
|
-// InetSocketAddress remoteAddress = exchange.getRequest().getRemoteAddress();
|
|
|
|
-// String clientIp = Objects.requireNonNull(remoteAddress).getAddress().getHostAddress();
|
|
|
|
-// ServerHttpRequest mutatedServerHttpRequest = exchange.getRequest().mutate().header("X-CLIENT-IP", clientIp).build();
|
|
|
|
-// ServerWebExchange mutatedServerWebExchange = exchange.mutate().request(mutatedServerHttpRequest).build();
|
|
|
|
-// return chain.filter(mutatedServerWebExchange);
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// /**
|
|
|
|
-// * 全局跨域配置
|
|
|
|
-// */
|
|
|
|
-// /*@Override
|
|
|
|
-// public void addCorsMappings(CorsRegistry registry) {
|
|
|
|
-// registry.addMapping("/**")
|
|
|
|
-// // 访问源地址
|
|
|
|
-// //.allowedOrigins("*")
|
|
|
|
-// .allowedOriginPatterns("*")
|
|
|
|
-// // 访问源请求方法
|
|
|
|
-// .allowedMethods("*")
|
|
|
|
-// // 访问源请求头
|
|
|
|
-// .allowedHeaders("*")
|
|
|
|
-// .exposedHeaders("Content-Type", "X-Requested-With", "accept", "Origin", "Access-Control-Request-Method", "Access-Control-Request-Headers")
|
|
|
|
-// .allowCredentials(true).maxAge(3600);
|
|
|
|
-// }*/
|
|
|
|
-//}
|
|
|
|
-//
|
|
|