22301014 | 6abadd7 | 2025-06-05 14:21:13 +0800 | [diff] [blame] | 1 | import axios from "axios"; |
22301014 | 6abadd7 | 2025-06-05 14:21:13 +0800 | [diff] [blame] | 2 | |
| 3 | // 为所有auth外请求添加token头 |
| 4 | axios.interceptors.request.use((config) => { |
| 5 | const requestUrl = config.url; |
| 6 | if (requestUrl?.includes("/auth/")) { |
| 7 | config.url = requestUrl.replace("/auth/","/"); |
| 8 | } else { |
| 9 | const token = localStorage.getItem('token'); |
22301014 | 6abadd7 | 2025-06-05 14:21:13 +0800 | [diff] [blame] | 10 | config.headers['Authorization'] = `Bearer ${token}`; |
| 11 | } |
| 12 | return config; |
| 13 | }, (error) => { |
| 14 | return error; |
22301023 | 71ee1c9 | 2025-06-05 16:18:32 +0800 | [diff] [blame] | 15 | } ); |
| 16 | |
| 17 | export default axios |