|
@@ -0,0 +1,25 @@
|
|
|
+package com.huimv.cattle.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;
|
|
|
+
|
|
|
+@Configuration
|
|
|
+public class CorsConfig {
|
|
|
+
|
|
|
+
|
|
|
+ @Bean
|
|
|
+ public CorsWebFilter corsFilter() {
|
|
|
+ CorsConfiguration config = new CorsConfiguration();
|
|
|
+ config.addAllowedMethod("*");
|
|
|
+ config.addAllowedOrigin("*");
|
|
|
+ config.addAllowedHeader("*");
|
|
|
+ config.setMaxAge(18000L);// 预检请求的缓存时间(秒),即在这个时间内,对于相同的跨域请求不会再预检了
|
|
|
+ UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
|
|
|
+ source.registerCorsConfiguration("/**", config);
|
|
|
+ return new CorsWebFilter(source);
|
|
|
+ }
|
|
|
+}
|