跨域处理
This commit is contained in:
parent
fbe37cc428
commit
edb9a17696
31
告警细节.txt
31
告警细节.txt
|
|
@ -98,4 +98,33 @@
|
|||
"alarmTime": "2022-05-10T05:06:22",
|
||||
"alarmEvent": "ws服务异常"
|
||||
}
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* 跨域配置
|
||||
*/
|
||||
@Bean
|
||||
public CorsFilter corsFilter()
|
||||
{
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
CorsConfiguration config = new CorsConfiguration();
|
||||
// 是否允许请求带有验证信息
|
||||
config.setAllowCredentials(true);
|
||||
|
||||
// 允许访问的客户端域名
|
||||
// (springboot2.4以上的加入这一段可解决 allowedOrigins cannot contain the special value "*"问题)
|
||||
List<String> allowedOriginPatterns = new ArrayList<>();
|
||||
allowedOriginPatterns.add("*");
|
||||
config.setAllowedOriginPatterns(allowedOriginPatterns);
|
||||
|
||||
// 设置访问源地址
|
||||
// config.addAllowedOrigin("*");
|
||||
// 设置访问源请求头
|
||||
config.addAllowedHeader("*");
|
||||
// 设置访问源请求方法
|
||||
config.addAllowedMethod("*");
|
||||
// 对接口配置跨域设置
|
||||
source.registerCorsConfiguration("/**", config);
|
||||
return new CorsFilter(source);
|
||||
}
|
||||
Loading…
Reference in New Issue