This commit is contained in:
lizhengwei 2026-03-27 21:06:12 +08:00
parent 594f45605b
commit c595249004

View File

@ -15,7 +15,6 @@ import org.springframework.web.servlet.config.annotation.*;
import java.util.List;
@Configuration
@EnableWebMvc
public class WebMvcConfig implements WebMvcConfigurer {
@Autowired
@ -53,25 +52,4 @@ public class WebMvcConfig implements WebMvcConfigurer {
registry.addInterceptor(new S3LoginUserInterceptor()).addPathPatterns("/storage/**");
}
/**
* 跨域配置
*/
@Bean
public CorsFilter corsFilter() {
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
// 设置访问源地址
config.addAllowedOriginPattern("*");
// 设置访问源请求头
config.addAllowedHeader("*");
// 设置访问源请求方法
config.addAllowedMethod("*");
// 有效期 1800秒
config.setMaxAge(1800L);
// 添加映射路径拦截一切请求
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", config);
// 返回新的CorsFilter
return new CorsFilter(source);
}
}