fix: compatible no api config case

This commit is contained in:
hongqiaowei
2020-12-09 18:24:01 +08:00
parent 6f7bfd7bbb
commit 0baeee474c
2 changed files with 10 additions and 6 deletions

View File

@@ -74,15 +74,18 @@ public class FizzGatewayFilter implements WebFilter {
@Resource
private ConfigLoader configLoader;
@NacosValue(value = "${need-auth:false}", autoRefreshed = true)
@Value("${need-auth:false}")
private boolean needAuth;
// @NacosValue(value = "${need-auth:false}", autoRefreshed = true)
// @Value("${need-auth:false}")
// private boolean needAuth;
@Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
String serviceId = WebUtils.getServiceId(exchange);
if (serviceId == null || (ApiConfig.Type.SERVICE_ARRANGE != WebUtils.getApiConfigType(exchange) && !needAuth) ) {
// if (serviceId == null || (ApiConfig.Type.SERVICE_ARRANGE != WebUtils.getApiConfigType(exchange) && !needAuth) ) {;
// return chain.filter(exchange);
// }
if (serviceId == null) {
return chain.filter(exchange);
}
@@ -94,7 +97,8 @@ public class FizzGatewayFilter implements WebFilter {
String method = request.getMethodValue();
AggregateResource aggregateResource = configLoader.matchAggregateResource(method, path);
if (aggregateResource == null) {
return WebUtils.responseError(exchange, HttpStatus.INTERNAL_SERVER_ERROR.value(), "no aggregate resource: " + path);
// return WebUtils.responseError(exchange, HttpStatus.INTERNAL_SERVER_ERROR.value(), "no aggregate resource: " + path);
return chain.filter(exchange);
}
Pipeline pipeline = aggregateResource.getPipeline();

View File

@@ -309,7 +309,7 @@ public class ApiConfigService {
}
ApiConfig ac = ac0;
if (ac == null) {
if (needAuth) {
if (!needAuth) {
return Mono.just(Access.YES);
} else {
return logWarnAndResult(api + " no api config", Access.NO_API_CONFIG);