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;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;
@ -13,6 +15,8 @@ import java.util.List;
*
* @author ruoyi
*/
@Setter
@Getter
@Configuration
@RefreshScope
@ConfigurationProperties(prefix = "security.ignore")
@ -23,13 +27,4 @@ public class IgnoreWhiteProperties
*/
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
{
private Mono<Void> writeResponse(ServerResponse response, ServerWebExchange exchange)
{
return ServletUtils.webFluxResponseWriter(exchange.getResponse(), "请求超过最大数,请稍候再试");
}
@Override
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));
}
private Mono<Void> writeResponse(ServerResponse response, ServerWebExchange exchange)
{
return ServletUtils.webFluxResponseWriter(exchange.getResponse(), "请求超过最大数,请稍候再试", 429);
}
private Mono<ServerResponse> handleBlockedRequest(ServerWebExchange exchange, Throwable throwable)
{
return GatewayCallbackManager.getBlockHandler().handleRequest(exchange, throwable);

View File

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