feat: 添加代码格式化

This commit is contained in:
lirui
2025-11-25 13:53:29 +08:00
parent 4304ec6e29
commit d89960f51c
72 changed files with 1403 additions and 1311 deletions

View File

@@ -5,10 +5,12 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@EnableConfigurationProperties(value = {GatewayPropertiesConfiguration.class})
@EnableConfigurationProperties(value = { GatewayPropertiesConfiguration.class })
@SpringBootApplication
public class AIOJGatewayApplication {
public static void main(String[] args) {
SpringApplication.run(AIOJGatewayApplication.class, args);
}
public static void main(String[] args) {
SpringApplication.run(AIOJGatewayApplication.class, args);
}
}

View File

@@ -12,57 +12,49 @@ import java.util.List;
/**
* 全局 CORS 配置WebFlux 环境使用 CorsWebFilter
*
* WebFlux 不使用 Spring MVC 的 CorsFilter
* 而是使用专门的 CorsWebFilter 处理跨域。
* WebFlux 不使用 Spring MVC 的 CorsFilter 而是使用专门的 CorsWebFilter 处理跨域。
*
* 此配置实现了:
* - 允许任意域名访问AllowedOriginPatterns = "*"
* - 允许所有请求方法GET、POST、PUT...
* - 允许所有请求头
* - 允许跨域携带 CookieAllowCredentials
* - 对所有路径生效(/**
* 此配置实现了: - 允许任意域名访问AllowedOriginPatterns = "*" - 允许所有请求方法GET、POST、PUT... - 允许所有请求头 -
* 允许跨域携带 CookieAllowCredentials - 对所有路径生效(/**
*/
@Configuration
public class CorsConfig {
/**
* 注册全局 CORS 过滤器
*
* @return CorsWebFilter 跨域过滤器
*/
@Bean
public CorsWebFilter corsWebFilter() {
/**
* 注册全局 CORS 过滤器
* @return CorsWebFilter 跨域过滤器
*/
@Bean
public CorsWebFilter corsWebFilter() {
// 创建跨域配置对象
CorsConfiguration corsConfiguration = new CorsConfiguration();
// 创建跨域配置对象
CorsConfiguration corsConfiguration = new CorsConfiguration();
// 允许所有请求方式GET、POST、PUT、DELETE、OPTIONS...
corsConfiguration.addAllowedMethod("*");
// 允许所有请求方式GET、POST、PUT、DELETE、OPTIONS...
corsConfiguration.addAllowedMethod("*");
// 是否允许携带 Cookie 信息。跨域默认不允许,需要显式开启
corsConfiguration.setAllowCredentials(true);
// 是否允许携带 Cookie 信息。跨域默认不允许,需要显式开启
corsConfiguration.setAllowCredentials(true);
/**
* 允许跨域的来源域名
* 使用 setAllowedOriginPatterns("*") 是 WebFlux 推荐方式,
* 因为 setAllowedOrigins("*") 在 allowCredentials=true 时会被拦截。
*/
corsConfiguration.setAllowedOriginPatterns(List.of("*"));
/**
* 允许跨域的来源域名 使用 setAllowedOriginPatterns("*") 是 WebFlux 推荐方式, 因为
* setAllowedOrigins("*") 在 allowCredentials=true 时会被拦截。
*/
corsConfiguration.setAllowedOriginPatterns(List.of("*"));
// 允许所有请求头,例如 Authorization、Content-Type 等
corsConfiguration.addAllowedHeader("*");
// 允许所有请求头,例如 Authorization、Content-Type 等
corsConfiguration.addAllowedHeader("*");
/**
* 基于 URL 的跨域配置源,
* PathPatternParser 用于解析路径模式(更高性能)
*/
UrlBasedCorsConfigurationSource source =
new UrlBasedCorsConfigurationSource(new PathPatternParser());
/**
* 基于 URL 的跨域配置源, PathPatternParser 用于解析路径模式(更高性能)
*/
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
// 对所有路径应用跨域设置
source.registerCorsConfiguration("/**", corsConfiguration);
// 对所有路径应用跨域设置
source.registerCorsConfiguration("/**", corsConfiguration);
// 创建并返回 WebFlux 专用的 CORS 过滤器
return new CorsWebFilter(source);
}
// 创建并返回 WebFlux 专用的 CORS 过滤器
return new CorsWebFilter(source);
}
}

View File

@@ -6,9 +6,12 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = GatewayPropertiesConfiguration.PREFIX)
@Data
public class GatewayPropertiesConfiguration {
public static final String PREFIX = "aioj-backend-gateway";
/*
* 白名单放行
* */
private String[] whiteList;
public static final String PREFIX = "aioj-backend-gateway";
/*
* 白名单放行
*/
private String[] whiteList;
}

View File

@@ -13,15 +13,16 @@ import reactor.core.publisher.Mono;
@RequiredArgsConstructor
public class AuthGlobalFilter implements GlobalFilter, Ordered {
private final WebClient.Builder webClientBuilder;
private final WebClient.Builder webClientBuilder;
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
return null;
}
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
return null;
}
@Override
public int getOrder() {
return 0;
}
@Override
public int getOrder() {
return 0;
}
}