Browse Source

tj

master
DESKTOP-8FESTBI\Administrator 8 months ago
parent
commit
7a5861e101

+ 4
- 1
RuoYi-Vue/ruoyi-admin/src/main/resources/application.yml View File

@@ -205,4 +205,7 @@ permit-all:
205 205
     - /druid/**
206 206
     - /swagger-ui/**
207 207
     - /v3/api-docs/**
208
-    - /webjars/**
208
+    - /webjars/**
209
+
210
+cors:
211
+  allowed-origins: http://localhost:9090

+ 0
- 19
RuoYi-Vue/ruoyi-framework/src/main/java/com/ruoyi/framework/config/CorsConfig.java View File

@@ -1,19 +0,0 @@
1
-package com.ruoyi.framework.config;
2
-
3
-import org.springframework.context.annotation.Configuration;
4
-import org.springframework.web.servlet.config.annotation.CorsRegistry;
5
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
6
-
7
-@Configuration
8
-public class CorsConfig implements WebMvcConfigurer {
9
-    @Override
10
-    public void addCorsMappings(CorsRegistry registry) {
11
-        registry.addMapping("/**")
12
-                // 使用 allowedOriginPatterns 替代 allowedOrigins
13
-                .allowedOriginPatterns("http://localhost:9090")
14
-                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
15
-                .allowedHeaders("*")
16
-                .allowCredentials(true)
17
-                .maxAge(3600);
18
-    }
19
-}

+ 18
- 6
RuoYi-Vue/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java View File

@@ -1,6 +1,8 @@
1 1
 package com.ruoyi.framework.config;
2 2
 
3
+
3 4
 import org.springframework.beans.factory.annotation.Autowired;
5
+import org.springframework.beans.factory.annotation.Value;
4 6
 import org.springframework.context.annotation.Bean;
5 7
 import org.springframework.context.annotation.Configuration;
6 8
 import org.springframework.http.HttpMethod;
@@ -24,6 +26,8 @@ import com.ruoyi.framework.security.filter.JwtAuthenticationTokenFilter;
24 26
 import com.ruoyi.framework.security.handle.AuthenticationEntryPointImpl;
25 27
 import com.ruoyi.framework.security.handle.LogoutSuccessHandlerImpl;
26 28
 
29
+import java.util.List;
30
+
27 31
 /**
28 32
  * spring security配置
29 33
  *
@@ -60,9 +64,11 @@ public class SecurityConfig
60 64
     /**
61 65
      * 跨域过滤器
62 66
      */
63
-    @Autowired
64
-    private CorsFilter corsFilter;
65
-
67
+    //@Autowired
68
+    //private CorsFilter corsFilter;
69
+// 代码中读取配置
70
+    @Value("${cors.allowed-origins}")
71
+    private List<String> allowedOrigins;
66 72
     /**
67 73
      * 允许匿名访问的地址
68 74
      */
@@ -104,7 +110,10 @@ public class SecurityConfig
104 110
         permitAllUrl.getUrls().add("/ad/**");
105 111
         permitAllUrl.getUrls().add("/swagger-ui/**");
106 112
         permitAllUrl.getUrls().add("/v3/api-docs/**");
107
-
113
+        // 确保登录相关接口也在白名单
114
+        permitAllUrl.getUrls().add("/login");
115
+        permitAllUrl.getUrls().add("/register");
116
+        permitAllUrl.getUrls().add("/captchaImage");
108 117
         http
109 118
                 // 禁用CSRF
110 119
                 .csrf(csrf -> csrf.disable())
@@ -147,7 +156,8 @@ public class SecurityConfig
147 156
                 // 添加JWT过滤器
148 157
                 .addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class)
149 158
                 // 添加CORS过滤器
150
-                .addFilterBefore(corsFilter, JwtAuthenticationTokenFilter.class);
159
+                //.addFilterBefore(corsFilter, JwtAuthenticationTokenFilter.class)
160
+                ;
151 161
 
152 162
         return http.build();
153 163
     }
@@ -155,7 +165,9 @@ public class SecurityConfig
155 165
     // CORS配置
156 166
     private CorsConfigurationSource corsConfigurationSource() {
157 167
         CorsConfiguration configuration = new CorsConfiguration();
158
-        configuration.addAllowedOrigin("*"); // 允许所有来源
168
+        configuration.setAllowedOriginPatterns(allowedOrigins);
169
+        //configuration.addAllowedOriginPattern("http://localhost:9090"); // 前端地址
170
+        //configuration.addAllowedOrigin("*"); // 允许所有来源
159 171
         configuration.addAllowedMethod("*"); // 允许所有方法
160 172
         configuration.addAllowedHeader("*"); // 允许所有头部
161 173
         configuration.setAllowCredentials(true); // 允许凭证

+ 10
- 1
RuoYi-Vue/ruoyi-system/src/main/java/com/ruoyi/novel/controller/NovelAdController.java View File

@@ -27,7 +27,16 @@ public class NovelAdController {
27 27
         this.iAdService = iAdService;
28 28
         this.redisTemplate = redisTemplate;
29 29
     }
30
-
30
+    // 修复广告接口
31
+//    @GetMapping("/position")
32
+//    public AjaxResult getAdByPosition(@RequestParam String code) {
33
+//        Ad ad = iAdService.selectAdByPositionCode(code);
34
+//        if (ad == null) {
35
+//            // 返回空对象而不是404
36
+//            return AjaxResult.success(new Ad());
37
+//        }
38
+//        return AjaxResult.success(ad);
39
+//    }
31 40
     @PostMapping("/count")
32 41
     public ResponseEntity<?> countAdView(
33 42
             @RequestBody AdCountRequest request,

+ 5
- 1
RuoYi-Vue/ruoyi-system/src/main/java/com/ruoyi/novel/controller/NovelController.java View File

@@ -52,7 +52,10 @@ public class NovelController extends BaseController {
52 52
 
53 53
     @GetMapping("/hot")
54 54
     public List<Novel> getHotNovels() {
55
-        return novelService.getHotNovels();
55
+        List<Novel> hotNovels = novelService.getHotNovels();
56
+        //return novelService.getHotNovels();
57
+        // 返回统一格式 { code, msg, data }
58
+        return (List<Novel>) AjaxResult.success(hotNovels);
56 59
     }
57 60
 
58 61
     // 获取分类列表
@@ -81,6 +84,7 @@ public class NovelController extends BaseController {
81 84
     public TableDataInfo list(Novel novel) {
82 85
         startPage();
83 86
         List<Novel> list = novelService.selectNovelOneList(novel);
87
+        System.out.println(list.size()+"条");
84 88
         // 关联分类名称
85 89
         list.forEach(n -> {
86 90
             NovelCategory category = (NovelCategory) novelService.getNovelsByCategory(n.getCategoryId());

Loading…
Cancel
Save