spring boot + shiro + vue(axios)采用cookie+session实现前后分离的生产环境跨域配置的笔记
笔记
采用cookie+session实现前后分离和使用web token的区别(前端异步采用axios)
1. web token 跨域配置
web token 这个前后端配置比较简单,后端只需要配置Origin为*,header为*就可以了
前端不需要怎么配置,头信息要传的什么就配置什么,如你需要传token可以设置
{
headers: {
'X-Authorization': 'token值'
}
}
然后后端获取头信息进行权限校验即可
//后端配置
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
/**
* 跨域请求设置 过滤器
*
*/
public class CustomCorsFilter extends CorsFilter {
public CustomCorsFilter() {
super(configurationSource());
}
private static UrlBasedCorsConfigurationSource configurationSource() {
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin("*");
config.addAllowedHeader("*");