Browse Source

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

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

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

@@ -31,10 +31,14 @@ spring:
31
         druid:
31
         druid:
32
             # 主库数据源
32
             # 主库数据源
33
             master:
33
             master:
34
-                url: jdbc:kingbase8://localhost:54321/postcheck
34
+#                url: jdbc:kingbase8://localhost:54321/postcheck
35
 #                url: jdbc:kingbase8://39.106.66.72:54321/postcheck
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
             slave:
43
             slave:
40
                 # 从数据源开关/默认关闭
44
                 # 从数据源开关/默认关闭

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

@@ -8,11 +8,11 @@ ruoyi:
8
   copyrightYear: 2023
8
   copyrightYear: 2023
9
   # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath)
9
   # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath)
10
 #  profile: c:/gnhz/uploadPath
10
 #  profile: c:/gnhz/uploadPath
11
-  profile: c:\gnhz\uploadPath
11
+#  profile: c:\gnhz\uploadPath
12
   # 惠州PC
12
   # 惠州PC
13
 #  profile: d:/postcheck/uploadPath
13
 #  profile: d:/postcheck/uploadPath
14
   # 生产环境
14
   # 生产环境
15
-#  profile: /opt/postcheck/jar/uploadPath
15
+  profile: /opt/postcheck/jar/uploadPath
16
   # 获取ip地址开关
16
   # 获取ip地址开关
17
   addressEnabled: false
17
   addressEnabled: false
18
   # 验证码类型 math 数字计算 char 字符验证
18
   # 验证码类型 math 数字计算 char 字符验证
@@ -58,9 +58,9 @@ spring:
58
     basename: i18n/messages
58
     basename: i18n/messages
59
   profiles:
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
   servlet:
65
   servlet:
66
     multipart:
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
         String[] allowDomain = {
28
         String[] allowDomain = {
29
                 "http://10.152.70.21:8080", // CAS服务器
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
                // "*.cnooc.*"
31
                // "*.cnooc.*"
32
                 // TODO 打包屏蔽-甲方部署时注释:甲方不需要本地登录功能采用单点登录
32
                 // TODO 打包屏蔽-甲方部署时注释:甲方不需要本地登录功能采用单点登录
33
-                "http://192.168.3.32:81"  // 前端开发
33
+//                ,"http://192.168.3.32:81"  // 前端开发
34
         };
34
         };
35
         Set<String> allowedOrigins = new HashSet<>(Arrays.asList(allowDomain));
35
         Set<String> allowedOrigins = new HashSet<>(Arrays.asList(allowDomain));
36
         String originHeader = request.getHeader("Origin");
36
         String originHeader = request.getHeader("Origin");
@@ -40,17 +40,13 @@ public class RestCorsFilter implements Filter {
40
             response.setHeader("Access-Control-Allow-Credentials", "true");
40
             response.setHeader("Access-Control-Allow-Credentials", "true");
41
             response.setHeader("Access-Control-Allow-Methods", "POST, GET, DELETE, PUT");
41
             response.setHeader("Access-Control-Allow-Methods", "POST, GET, DELETE, PUT");
42
             response.setHeader("Access-Control-Max-Age", "31536000");
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
         } else {
45
         } else {
45
             response.setStatus(HttpServletResponse.SC_FORBIDDEN);
46
             response.setStatus(HttpServletResponse.SC_FORBIDDEN);
46
             return;
47
             return;
47
         }
48
         }
48
-
49
-        if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
50
-            response.setStatus(HttpServletResponse.SC_OK);
51
-        } else {
52
             chain.doFilter(req, res);
49
             chain.doFilter(req, res);
53
-        }
54
     }
50
     }
55
 
51
 
56
     @Override
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
         // 返回新的CorsFilter
70
         // 返回新的CorsFilter
71
         return new CorsFilter(source);
71
         return new CorsFilter(source);
72
     }
72
     }
73
-}
73
+}