fzzj 8 kuukautta sitten
vanhempi
commit
112a71d2fd

+ 11
- 1
RuoYi-App/utils/request.js Näytä tiedosto

@@ -72,7 +72,17 @@ function request(method, url, data = {}, options = {}) {
72 72
     })
73 73
   })
74 74
 }
75
-
75
+service.interceptors.request.use(config => {
76
+  // 从Vuex或localStorage获取token
77
+  const token = store.state.token || localStorage.getItem('token');
78
+  
79
+  if (token) {
80
+    config.headers['Authorization'] = `Bearer ${token}`;
81
+  }
82
+  return config;
83
+}, error => {
84
+  return Promise.reject(error);
85
+});
76 86
 // 导出对象以兼容旧代码
77 87
 export default {
78 88
   get,

+ 9
- 4
RuoYi-App/vue.config.js Näytä tiedosto

@@ -1,15 +1,20 @@
1
+// vue.config.js
1 2
 module.exports = {
2 3
   devServer: {
3 4
     proxy: {
4
-      '/java-api': {  // 确保匹配请求路径前缀
5
-        target: 'http://localhost:8080', // 替换为实际后端地址
5
+      '/java-api': {
6
+        target: 'http://localhost:8080',
6 7
         changeOrigin: true,
7
-        pathRewrite: { '^/java-api': '' } // 去除路径前缀
8
+        pathRewrite: { 
9
+          '^/java-api': '/java-api' // 保持原始路径
10
+        }
8 11
       },
9 12
       '/api': {
10 13
         target: 'http://localhost:8080',
11 14
         changeOrigin: true,
12
-        pathRewrite: { '^/api': '' }
15
+        pathRewrite: { 
16
+          '^/api': '/api' // 修正路径重写规则
17
+        }
13 18
       }
14 19
     }
15 20
   }

+ 11
- 0
RuoYi-Vue/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java Näytä tiedosto

@@ -127,7 +127,18 @@ public class SecurityConfig
127 127
             .addFilterBefore(corsFilter, LogoutFilter.class)
128 128
             .build();
129 129
     }
130
+    // SecurityConfig.java
130 131
 
132
+    protected void configure(HttpSecurity http) throws Exception {
133
+        http
134
+                .authorizeRequests()
135
+                .antMatchers("/api/novel/list").permitAll() // 放行小说列表
136
+                .antMatchers("/java-api/category/tree").permitAll() // 放行分类
137
+                .antMatchers("/api/novel/hot").permitAll() // 放行热门小说
138
+                .anyRequest().authenticated()
139
+                .and()
140
+                .csrf().disable();
141
+    }
131 142
     /**
132 143
      * 强散列哈希加密实现
133 144
      */

+ 1
- 1
RuoYi-Vue/ruoyi-system/src/main/java/com/ruoyi/novel/controller/NovelController.java Näytä tiedosto

@@ -29,7 +29,7 @@ import java.util.concurrent.CompletableFuture;
29 29
 
30 30
 // NovelController.java
31 31
 @RestController
32
-@RequestMapping("/novel")
32
+@RequestMapping("/api/novel")
33 33
 public class NovelController extends BaseController {
34 34
 
35 35
 

Loading…
Peruuta
Tallenna