1. 调整 gateway

This commit is contained in:
ant 2024-05-24 15:47:59 +08:00
parent 08f9de153f
commit 45e5e2bc49
3 changed files with 18 additions and 15 deletions

View File

@ -1,5 +1,7 @@
package com.chushang.gateway.config.properties; package com.chushang.gateway.config.properties;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -13,6 +15,8 @@ import java.util.List;
* *
* @author ruoyi * @author ruoyi
*/ */
@Setter
@Getter
@Configuration @Configuration
@RefreshScope @RefreshScope
@ConfigurationProperties(prefix = "security.ignore") @ConfigurationProperties(prefix = "security.ignore")
@ -23,13 +27,4 @@ public class IgnoreWhiteProperties
*/ */
private List<String> whites = new ArrayList<>(); private List<String> whites = new ArrayList<>();
public List<String> getWhites()
{
return whites;
}
public void setWhites(List<String> whites)
{
this.whites = whites;
}
} }

View File

@ -15,10 +15,6 @@ import reactor.core.publisher.Mono;
*/ */
public class SentinelFallbackHandler implements WebExceptionHandler public class SentinelFallbackHandler implements WebExceptionHandler
{ {
private Mono<Void> writeResponse(ServerResponse response, ServerWebExchange exchange)
{
return ServletUtils.webFluxResponseWriter(exchange.getResponse(), "请求超过最大数,请稍候再试");
}
@Override @Override
public Mono<Void> handle(ServerWebExchange exchange, Throwable ex) public Mono<Void> handle(ServerWebExchange exchange, Throwable ex)
@ -34,6 +30,12 @@ public class SentinelFallbackHandler implements WebExceptionHandler
return handleBlockedRequest(exchange, ex).flatMap(response -> writeResponse(response, exchange)); return handleBlockedRequest(exchange, ex).flatMap(response -> writeResponse(response, exchange));
} }
private Mono<Void> writeResponse(ServerResponse response, ServerWebExchange exchange)
{
return ServletUtils.webFluxResponseWriter(exchange.getResponse(), "请求超过最大数,请稍候再试", 429);
}
private Mono<ServerResponse> handleBlockedRequest(ServerWebExchange exchange, Throwable throwable) private Mono<ServerResponse> handleBlockedRequest(ServerWebExchange exchange, Throwable throwable)
{ {
return GatewayCallbackManager.getBlockHandler().handleRequest(exchange, throwable); return GatewayCallbackManager.getBlockHandler().handleRequest(exchange, throwable);

View File

@ -64,7 +64,11 @@ spring:
- Path=/api/job/** - Path=/api/job/**
filters: filters:
- StripPrefix=1 - StripPrefix=1
#default-filters: # default-filters:
# - name: BlackListUrlFilter
# args:
# blacklistUrl:
# - /test
# - DedupeResponseHeader=Access-Control-Allow-Credentials Access-Control-Allow-Origin # - DedupeResponseHeader=Access-Control-Allow-Credentials Access-Control-Allow-Origin
# # 默认限流 # # 默认限流
# - name: RequestRateLimiter # - name: RequestRateLimiter
@ -79,6 +83,8 @@ spring:
# # 一个请求需要多少令牌 这是为每个请求从桶中获取的令牌数量默认为1。 # # 一个请求需要多少令牌 这是为每个请求从桶中获取的令牌数量默认为1。
# redis-rate-limiter.requestedTokens: 1 # redis-rate-limiter.requestedTokens: 1
# key-resolver: "#{@remoteAddrKeyResolver}" # key-resolver: "#{@remoteAddrKeyResolver}"
# 安全配置 # 安全配置
security: security:
# 验证码 # 验证码
@ -96,7 +102,7 @@ security:
- /auth/logout - /auth/logout
- /auth/login - /auth/login
- /auth/register - /auth/register
- /manager/remote/** - /feign/**
- /demo/** - /demo/**
logging: logging:
config: classpath:logback-nacos.xml config: classpath:logback-nacos.xml