From 644fc2c4817d759195c016bcac80f43ec6540dfc Mon Sep 17 00:00:00 2001
From: 林致杰 <1003392067@qq.com>
Date: 星期四, 19 十月 2023 18:40:53 +0800
Subject: [PATCH] bugfix

---
 src/main/java/com/ots/framework/config/ResourcesConfig.java |   43 ++++++++++++++++++++++++++++++++++---------
 1 files changed, 34 insertions(+), 9 deletions(-)

diff --git a/src/main/java/com/ots/framework/config/ResourcesConfig.java b/src/main/java/com/ots/framework/config/ResourcesConfig.java
index e9d2106..5822c7b 100644
--- a/src/main/java/com/ots/framework/config/ResourcesConfig.java
+++ b/src/main/java/com/ots/framework/config/ResourcesConfig.java
@@ -1,36 +1,61 @@
 package com.ots.framework.config;
+
 import com.ots.framework.interceptor.RepeatSubmitInterceptor;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
-import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
-import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
-import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+import org.springframework.web.cors.CorsConfiguration;
+import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
+import org.springframework.web.filter.CorsFilter;
+import org.springframework.web.servlet.config.annotation.*;
 
 @Configuration
 public class ResourcesConfig implements WebMvcConfigurer {
-    
+
     @Value("${shiro.user.indexUrl}")
     private String indexUrl;
     @Autowired
     private RepeatSubmitInterceptor repeatSubmitInterceptor;
-    
+
     @Override
     public void addViewControllers(ViewControllerRegistry registry) {
         registry.addViewController("/").setViewName("forward:" + indexUrl);
     }
+
     @Override
     public void addResourceHandlers(ResourceHandlerRegistry registry) {
-        
+
         registry.addResourceHandler("/profile/**").addResourceLocations("file:" + EssConfig.getProfile() + "/");
-        
+
         registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
         registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
     }
-    
+
     @Override
     public void addInterceptors(InterceptorRegistry registry) {
         registry.addInterceptor(repeatSubmitInterceptor).addPathPatterns("/**");
     }
+
+    /**
+     * 璺ㄥ煙閰嶇疆
+     */
+    @Bean
+    public CorsFilter corsFilter() {
+        CorsConfiguration config = new CorsConfiguration();
+        config.setAllowCredentials(true);
+        // 璁剧疆璁块棶婧愬湴鍧�
+        config.addAllowedOrigin("*");
+        // 璁剧疆璁块棶婧愯姹傚ご
+        config.addAllowedHeader("*");
+        // 璁剧疆璁块棶婧愯姹傛柟娉�
+        config.addAllowedMethod("*");
+        // 鏈夋晥鏈� 1800绉�
+        config.setMaxAge(1800L);
+        // 娣诲姞鏄犲皠璺緞锛屾嫤鎴竴鍒囪姹�
+        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
+        source.registerCorsConfiguration("/**", config);
+        // 杩斿洖鏂扮殑CorsFilter
+        return new CorsFilter(source);
+    }
 }

--
Gitblit v1.9.1