File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
api-gateway/src/main/java/cn/algerfan/apigateway/config Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ package cn .algerfan .apigateway .config ;
2
+
3
+ import org .springframework .context .annotation .Bean ;
4
+ import org .springframework .context .annotation .Configuration ;
5
+ import org .springframework .web .cors .CorsConfiguration ;
6
+ import org .springframework .web .cors .UrlBasedCorsConfigurationSource ;
7
+ import org .springframework .web .filter .CorsFilter ;
8
+
9
+ import java .util .Collections ;
10
+
11
+ /**
12
+ * Zuul跨域
13
+ * @author algerfan
14
+ * @time 2019/8/29 11:18
15
+ */
16
+ @ Configuration
17
+ public class CorsConfig {
18
+
19
+ @ Bean
20
+ public CorsFilter corsFilter () {
21
+ final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource ();
22
+ final CorsConfiguration configuration = new CorsConfiguration ();
23
+ configuration .setAllowCredentials (true );
24
+ configuration .setAllowedHeaders (Collections .singletonList ("*" ));
25
+ //setAllowedOrigins为http://www.a.com
26
+ configuration .setAllowedOrigins (Collections .singletonList ("*" ));
27
+ configuration .setAllowedMethods (Collections .singletonList ("*" ));
28
+ configuration .setMaxAge (300L );
29
+ source .registerCorsConfiguration ("/**" , configuration );
30
+ return new CorsFilter (source );
31
+ }
32
+
33
+ }
You can’t perform that action at this time.
0 commit comments