mirror of
https://github.com/201206030/novel.git
synced 2025-04-27 07:30:50 +00:00
feat(CorsConfig.java): 增加跨域配置
This commit is contained in:
parent
cd8fcf9dbe
commit
8dcaf5f7fe
@ -0,0 +1,35 @@
|
|||||||
|
package io.github.xxyopen.novel.core.common.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.cors.CorsConfiguration;
|
||||||
|
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||||
|
import org.springframework.web.filter.CorsFilter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 跨域配置
|
||||||
|
*
|
||||||
|
* @author xiongxiaoyang
|
||||||
|
* @date 2022/5/13
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class CorsConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public CorsFilter corsFilter() {
|
||||||
|
CorsConfiguration config = new CorsConfiguration();
|
||||||
|
// 允许的域,不要写*,否则cookie就无法使用了
|
||||||
|
config.addAllowedOrigin("http://localhost:1024");
|
||||||
|
// 允许的头信息
|
||||||
|
config.addAllowedHeader("*");
|
||||||
|
// 允许的请求方式
|
||||||
|
config.addAllowedMethod("*");
|
||||||
|
// 是否允许携带Cookie信息
|
||||||
|
config.setAllowCredentials(true);
|
||||||
|
|
||||||
|
UrlBasedCorsConfigurationSource configurationSource = new UrlBasedCorsConfigurationSource();
|
||||||
|
// 添加映射路径,拦截一切请求
|
||||||
|
configurationSource.registerCorsConfiguration("/**",config);
|
||||||
|
return new CorsFilter(configurationSource);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user