guonan
2025-05-01 0d4c3c3877bee1c92f574d26c67118dadb4a3dc7
src/api/requestTR.js
@@ -1,13 +1,26 @@
import axios from "axios";
// 判断当前是否是开发环境
let API_URL;
if (process.env.NODE_ENV === 'development') {
  // 开发环境使用 '/api'
  API_URL = '/api';
} else {
  // 生产环境使用实际的配置地址
  API_URL = `${BASE_URL.endsWith('/') ? BASE_URL.slice(0, -1) : BASE_URL}/api`;
}
// 创建 Axios 实例
const instance = axios.create({
  baseURL: "/api", // 使用你配置的 /auth 代理
  baseURL: API_URL,
  timeout: 1000 * 60, // 请求超时时间(单位:毫秒)
  headers: {
    "Content-Type": "application/x-www-form-urlencoded", // 默认请求头application/json
    "Content-Type": "application/x-www-form-urlencoded", // 默认请求头
  },
});
console.log('当前 BaseUrl:', API_URL);
// 请求拦截器
// instance.interceptors.request.use(
//   (config) => {