Sfoglia il codice sorgente

CORS跨域过滤器中添加响应头

csg6 1 settimana fa
parent
commit
6b6b6bff5f

+ 1 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java

@@ -43,7 +43,7 @@ public class SysLoginController {
43 43
      * @return 结果
44 44
      */
45 45
     //TODO 打包屏蔽-甲方部署时注释:甲方不需要本地登录功能采用单点登录
46
-    /*@PostMapping("/login")
46
+  /*  @PostMapping("/login")
47 47
     public AjaxResult login(@RequestBody LoginBody loginBody) {
48 48
         AjaxResult ajax = AjaxResult.success();
49 49
 

+ 7 - 3
ruoyi-admin/src/main/resources/application-druid-dev.yml

@@ -31,10 +31,14 @@ spring:
31 31
         druid:
32 32
             # 主库数据源
33 33
             master:
34
-                url: jdbc:kingbase8://localhost:54321/postcheck
34
+#                url: jdbc:kingbase8://localhost:54321/postcheck
35 35
 #                url: jdbc:kingbase8://39.106.66.72:54321/postcheck
36
-                username: postcheckuser
37
-                password: Hzsh.eitc@6626.pcu
36
+#                username: postcheckuser
37
+#                password: Hzsh.eitc@6626.pcu
38
+
39
+                url: jdbc:kingbase8://192.168.3.242:54321/postcheck
40
+                username: system
41
+                password: 123456
38 42
             # 从库数据源
39 43
             slave:
40 44
                 # 从数据源开关/默认关闭

+ 4 - 4
ruoyi-admin/src/main/resources/application.yml

@@ -8,11 +8,11 @@ ruoyi:
8 8
   copyrightYear: 2023
9 9
   # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath)
10 10
 #  profile: c:/gnhz/uploadPath
11
-  profile: c:\gnhz\uploadPath
11
+#  profile: c:\gnhz\uploadPath
12 12
   # 惠州PC
13 13
 #  profile: d:/postcheck/uploadPath
14 14
   # 生产环境
15
-#  profile: /opt/postcheck/jar/uploadPath
15
+  profile: /opt/postcheck/jar/uploadPath
16 16
   # 获取ip地址开关
17 17
   addressEnabled: false
18 18
   # 验证码类型 math 数字计算 char 字符验证
@@ -58,9 +58,9 @@ spring:
58 58
     basename: i18n/messages
59 59
   profiles:
60 60
 # 本地开发时
61
-#    active: druid-dev,cas-dev
61
+    active: druid-dev,cas-dev
62 62
 # 甲方部署时
63
-    active: druid-test,cas-test
63
+#    active: druid-test,cas-test
64 64
   # 文件上传
65 65
   servlet:
66 66
     multipart:

+ 4 - 8
ruoyi-common/src/main/java/com/ruoyi/common/filter/RestCorsFilter.java

@@ -27,10 +27,10 @@ public class RestCorsFilter implements Filter {
27 27
         // 允许的来源
28 28
         String[] allowDomain = {
29 29
                 "http://10.152.70.21:8080", // CAS服务器
30
-                "http://10.152.72.7:8181" ,// 岗检前端Nginx
30
+                "http://10.152.72.7:8181" // 岗检前端Nginx
31 31
                // "*.cnooc.*"
32 32
                 // TODO 打包屏蔽-甲方部署时注释:甲方不需要本地登录功能采用单点登录
33
-                "http://192.168.3.32:81"  // 前端开发
33
+//                ,"http://192.168.3.32:81"  // 前端开发
34 34
         };
35 35
         Set<String> allowedOrigins = new HashSet<>(Arrays.asList(allowDomain));
36 36
         String originHeader = request.getHeader("Origin");
@@ -40,17 +40,13 @@ public class RestCorsFilter implements Filter {
40 40
             response.setHeader("Access-Control-Allow-Credentials", "true");
41 41
             response.setHeader("Access-Control-Allow-Methods", "POST, GET, DELETE, PUT");
42 42
             response.setHeader("Access-Control-Max-Age", "31536000");
43
-            response.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization, X-Requested-With");
43
+            response.setHeader("Access-Control-Allow-Headers", "*");
44
+            response.setStatus(HttpServletResponse.SC_OK);
44 45
         } else {
45 46
             response.setStatus(HttpServletResponse.SC_FORBIDDEN);
46 47
             return;
47 48
         }
48
-
49
-        if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
50
-            response.setStatus(HttpServletResponse.SC_OK);
51
-        } else {
52 49
             chain.doFilter(req, res);
53
-        }
54 50
     }
55 51
 
56 52
     @Override

+ 1 - 1
ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java

@@ -70,4 +70,4 @@ public class ResourcesConfig implements WebMvcConfigurer
70 70
         // 返回新的CorsFilter
71 71
         return new CorsFilter(source);
72 72
     }
73
-}
73
+}