增加跨域配置
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
# ms-getaway 服务网关项目说明
|
||||
## 添加支持跨域配置
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.micro.fast.gateway.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
|
||||
/**
|
||||
* 网关web配置类
|
||||
* @author lsy
|
||||
*/
|
||||
@Configuration
|
||||
public class WebConfig extends WebMvcConfigurerAdapter{
|
||||
|
||||
/**
|
||||
* 网关支持跨域配置,跨域问题需要在网关解决
|
||||
* @param registry
|
||||
*/
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry
|
||||
//允许请求的路径
|
||||
.addMapping("/**")
|
||||
//能给这个服务器发起请求的url
|
||||
.allowedOrigins("*")
|
||||
//允许的请求头为全部
|
||||
.allowedHeaders("*")
|
||||
//允许cookie跨域
|
||||
.allowCredentials(true)
|
||||
//允许的请求类型
|
||||
.allowedMethods("GET", "POST", "DELETE", "PUT")
|
||||
//预请求的校验时间间隔为6小时
|
||||
.maxAge(60*60*6L);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user