安全扫描修复

This commit is contained in:
gaowdong 2025-06-25 16:17:49 +08:00
parent 3214250e09
commit 5e83e5dbdd
1 changed files with 4 additions and 0 deletions

View File

@ -1,7 +1,9 @@
package com.bonus.gateway.config;
import cn.hutool.core.collection.CollUtil;
import com.alibaba.nacos.common.utils.JacksonUtils;
import com.bonus.gateway.config.properties.CorsProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -14,6 +16,7 @@ import org.springframework.web.util.pattern.PathPatternParser;
* Description 全局跨域配置
*/
@Configuration
@Slf4j
public class GlobalCorsConfig {
@Autowired
private CorsProperties corsProperties;
@ -24,6 +27,7 @@ public class GlobalCorsConfig {
// 允许所有的HTTP请求方法GET, POST, PUT, DELETE等
config.addAllowedMethod("*");
// 允许所有的域名发起的请求 比如http://localhost:8080
log.info("允许的域名:{}", corsProperties.getAllowedOrigins());
if(CollUtil.isNotEmpty(corsProperties.getAllowedOrigins())) {
for(String cors : corsProperties.getAllowedOrigins()) {
config.addAllowedOrigin(cors);