diff --git a/bonus-auth/src/main/resources/bootstrap.yml b/bonus-auth/src/main/resources/bootstrap.yml index 7051969..303ea0f 100644 --- a/bonus-auth/src/main/resources/bootstrap.yml +++ b/bonus-auth/src/main/resources/bootstrap.yml @@ -5,7 +5,7 @@ spring: name: bonus-auth profiles: # 环境配置 - active: dev + active: smart_canteen_local #加密组件 jasypt: diff --git a/bonus-gateway/src/main/java/com/bonus/gateway/config/GlobalCorsConfig.java b/bonus-gateway/src/main/java/com/bonus/gateway/config/GlobalCorsConfig.java new file mode 100644 index 0000000..223ee47 --- /dev/null +++ b/bonus-gateway/src/main/java/com/bonus/gateway/config/GlobalCorsConfig.java @@ -0,0 +1,33 @@ +package com.bonus.gateway.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.reactive.CorsWebFilter; +import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource; +import org.springframework.web.util.pattern.PathPatternParser; + +/** + * Description: 全局跨域配置 + */ +@Configuration +public class GlobalCorsConfig { + @Bean + public CorsWebFilter corsFilter() { + // 创建一个新的CorsConfiguration对象,用于配置跨域请求 + CorsConfiguration config = new CorsConfiguration(); + // 允许所有的HTTP请求方法(GET, POST, PUT, DELETE等) + config.addAllowedMethod("*"); + // 允许所有的域名发起的请求 比如http://localhost:8080、 + config.addAllowedOrigin("*"); + // 允许所有的域名发起的请求(支持正则表达式) 比如http://localhost:8080 + config.addAllowedOriginPattern("*"); + // 允许所有的请求头部信息 比如token、Content-Type + config.addAllowedHeader("*"); + // 创建一个UrlBasedCorsConfigurationSource对象,并使用PathPatternParser进行路径匹配 + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser()); + // 注册跨域配置,应用于所有的URL路径 + source.registerCorsConfiguration("/**", config); + return new CorsWebFilter(source); + } +} \ No newline at end of file diff --git a/bonus-gateway/src/main/resources/bootstrap.yml b/bonus-gateway/src/main/resources/bootstrap.yml index 1766a04..c23f027 100644 --- a/bonus-gateway/src/main/resources/bootstrap.yml +++ b/bonus-gateway/src/main/resources/bootstrap.yml @@ -5,7 +5,7 @@ spring: name: bonus-gateway profiles: # 环境配置 - active: dev + active: smart_canteen_local #加密组件 jasypt: diff --git a/bonus-modules/bonus-file/src/main/resources/bootstrap.yml b/bonus-modules/bonus-file/src/main/resources/bootstrap.yml index 371813f..5db6e57 100644 --- a/bonus-modules/bonus-file/src/main/resources/bootstrap.yml +++ b/bonus-modules/bonus-file/src/main/resources/bootstrap.yml @@ -6,7 +6,7 @@ spring: profiles: # 环境配置 - active: dev + active: smart_canteen_local #加密组件 jasypt: diff --git a/bonus-modules/bonus-system/src/main/resources/bootstrap.yml b/bonus-modules/bonus-system/src/main/resources/bootstrap.yml index 790dc0d..b1e8a47 100644 --- a/bonus-modules/bonus-system/src/main/resources/bootstrap.yml +++ b/bonus-modules/bonus-system/src/main/resources/bootstrap.yml @@ -5,7 +5,7 @@ spring: name: bonus-system profiles: # 环境配置 - active: dev + active: smart_canteen_local task: scheduling: pool: