yumeng 1 день назад
Родитель
Сommit
82a8b9d126

+ 2 - 0
ruixuan-framework/src/main/java/com/ruixuan/framework/config/ResourcesConfig.java

@@ -59,6 +59,8 @@ public class ResourcesConfig implements WebMvcConfigurer
         config.addAllowedHeader("*");
         // 设置访问源请求方法
         config.addAllowedMethod("*");
+        // 暴露响应头
+        config.addExposedHeader("*");
         // 有效期 1800秒
         config.setMaxAge(1800L);
         // 添加映射路径,拦截一切请求

+ 4 - 0
ruixuan-framework/src/main/java/com/ruixuan/framework/config/SecurityConfig.java

@@ -87,12 +87,16 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
         httpSecurity
                 // CSRF禁用,因为不使用session
                 .csrf().disable()
+                // 允许跨域预检请求
+                .cors().and()
                 // 认证失败处理类
                 .exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
                 // 基于token,所以不需要session
                 .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
                 // 过滤请求
                 .authorizeRequests()
+                // 放行 OPTIONS 预检请求
+                .antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
                 // 对于登录login 注册register 验证码captchaImage 允许匿名访问
                 .antMatchers("/login", "/register", "/captchaImage").anonymous()
                 .antMatchers(