请求跨域问题修复

wxpay
LI-CCONG\李聪聪 7 months ago
parent 01598d25d8
commit 56c31fd1d7

@ -79,18 +79,18 @@ public class WebMvcConfig implements WebMvcConfigurer {
}
/**
*
*/
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**") // 所有接口
.allowCredentials(true) // 是否发送 Cookie
.allowedOriginPatterns("*") // 支持域
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") // 支持方法
.allowedHeaders("*")
.exposedHeaders("*");
}
// /**
// * 跨域问题
// */
// @Override
// public void addCorsMappings(CorsRegistry registry) {
// registry.addMapping("/**") // 所有接口
// .allowCredentials(true) // 是否发送 Cookie
// .allowedOriginPatterns("*") // 支持域
// .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") // 支持方法
// .allowedHeaders("*")
// .exposedHeaders("*");
// }
/**

@ -0,0 +1,29 @@
package cc.yunxi.filter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
/**
* @Author ccongli
* @Date 2024/03/13 15:48
*/
@Configuration
public class HttpCorsFilter {
@Bean
public CorsFilter corsFilter() {
CorsConfiguration config = new CorsConfiguration();
config.addAllowedOriginPattern("*");
config.addAllowedMethod("*");
config.addAllowedHeader("*");
config.setAllowCredentials(true);
config.setMaxAge(3600L);
UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource();
configSource.registerCorsConfiguration("/**", config);
return new CorsFilter(configSource);
}
}
Loading…
Cancel
Save