forked from macrozheng/mall-swarm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
46e6170
commit a424275
Showing
2 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
mall-gateway/src/main/java/com/macro/mall/config/GlobalCorsConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.macro.mall.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; | ||
|
||
/** | ||
* 全局跨域配置 | ||
* 注意:前端从网关进行调用时需要配置 | ||
* Created by macro on 2019/7/27. | ||
*/ | ||
@Configuration | ||
public class GlobalCorsConfig { | ||
|
||
@Bean | ||
public CorsWebFilter corsFilter() { | ||
CorsConfiguration config = new CorsConfiguration(); | ||
config.addAllowedMethod("*"); | ||
config.addAllowedOrigin("*"); | ||
config.addAllowedHeader("*"); | ||
|
||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser()); | ||
source.registerCorsConfiguration("/**", config); | ||
|
||
return new CorsWebFilter(source); | ||
} | ||
|
||
} |