|
@@ -1,15 +1,9 @@
|
1
|
1
|
package com.community.huiju;
|
2
|
2
|
|
3
|
|
-//import com.didispace.swagger.butler.EnableSwaggerButler;
|
4
|
3
|
import org.springframework.boot.SpringApplication;
|
5
|
4
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
6
|
|
-import org.springframework.boot.autoconfigure.SpringBootApplication;
|
7
|
5
|
import org.springframework.cloud.client.SpringCloudApplication;
|
8
|
|
-import org.springframework.cloud.client.discovery.DiscoveryClient;
|
9
|
6
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
10
|
|
-import org.springframework.cloud.gateway.discovery.DiscoveryClientRouteDefinitionLocator;
|
11
|
|
-import org.springframework.cloud.gateway.discovery.DiscoveryLocatorProperties;
|
12
|
|
-import org.springframework.cloud.gateway.route.RouteDefinitionLocator;
|
13
|
7
|
import org.springframework.context.annotation.Bean;
|
14
|
8
|
import org.springframework.context.annotation.PropertySource;
|
15
|
9
|
import org.springframework.web.cors.CorsConfiguration;
|
|
@@ -34,24 +28,24 @@ public class GatewayApplication {
|
34
|
28
|
* * 反之,就是非简单跨域,此跨域有一个预检机制,说直白点,就是会发两次请求,一次OPTIONS请求,一次真正的请求
|
35
|
29
|
*
|
36
|
30
|
*/
|
37
|
|
-// @Bean
|
38
|
|
-// public CorsFilter corsFilter() {
|
39
|
|
-// final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
40
|
|
-// final CorsConfiguration config = new CorsConfiguration();
|
41
|
|
-// config.setAllowCredentials(true); // 允许cookies跨域
|
42
|
|
-// config.addAllowedOrigin("*");// #允许向该服务器提交请求的URI,*表示全部允许,在SpringMVC中,如果设成*,会自动转成当前请求头中的Origin
|
43
|
|
-// config.addAllowedHeader("*");// #允许访问的头信息,*表示全部
|
44
|
|
-// config.setMaxAge(18000L);// 预检请求的缓存时间(秒),即在这个时间段里,对于相同的跨域请求不会再预检了
|
45
|
|
-// config.addAllowedMethod("OPTIONS");// 允许提交请求的方法,*表示全部允许
|
46
|
|
-// config.addAllowedMethod("HEAD");
|
47
|
|
-// config.addAllowedMethod("GET");// 允许Get的请求方法
|
48
|
|
-// config.addAllowedMethod("PUT");
|
49
|
|
-// config.addAllowedMethod("POST");
|
50
|
|
-// config.addAllowedMethod("DELETE");
|
51
|
|
-// config.addAllowedMethod("PATCH");
|
52
|
|
-// source.registerCorsConfiguration("/**", config);
|
53
|
|
-// return new CorsFilter(source);
|
54
|
|
-// }
|
|
31
|
+ @Bean
|
|
32
|
+ public CorsFilter corsFilter() {
|
|
33
|
+ final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
|
34
|
+ final CorsConfiguration config = new CorsConfiguration();
|
|
35
|
+ config.setAllowCredentials(true); // 允许cookies跨域
|
|
36
|
+ config.addAllowedOrigin("*");// #允许向该服务器提交请求的URI,*表示全部允许,在SpringMVC中,如果设成*,会自动转成当前请求头中的Origin
|
|
37
|
+ config.addAllowedHeader("*");// #允许访问的头信息,*表示全部
|
|
38
|
+ config.setMaxAge(18000L);// 预检请求的缓存时间(秒),即在这个时间段里,对于相同的跨域请求不会再预检了
|
|
39
|
+ config.addAllowedMethod("OPTIONS");// 允许提交请求的方法,*表示全部允许
|
|
40
|
+ config.addAllowedMethod("HEAD");
|
|
41
|
+ config.addAllowedMethod("GET");// 允许Get的请求方法
|
|
42
|
+ config.addAllowedMethod("PUT");
|
|
43
|
+ config.addAllowedMethod("POST");
|
|
44
|
+ config.addAllowedMethod("DELETE");
|
|
45
|
+ config.addAllowedMethod("PATCH");
|
|
46
|
+ source.registerCorsConfiguration("/**", config);
|
|
47
|
+ return new CorsFilter(source);
|
|
48
|
+ }
|
55
|
49
|
|
56
|
50
|
|
57
|
51
|
}
|