{"size": 1747, "ext": "js", "max_stars_repo_path": "src/app/api/index.js", "max_stars_repo_name": "bitores/ng-antd-super-form", "max_stars_repo_stars_event_min_datetime": "2019-11-25T10:13:00.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-25T10:13:00.000Z", "max_issues_repo_path": "src/app/api/index.js", "max_issues_repo_name": "bitores/ng-antd-super-form", "max_issues_repo_issues_event_min_datetime": "2020-09-07T05:01:28.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T17:30:50.000Z", "max_forks_repo_path": "src/app/api/index.js", "max_forks_repo_name": "bitores/ng-antd-super-form", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 8, "max_forks_count": null, "avg_line_length": 24.6056338028, "max_line_length": 65, "alphanum_fraction": 0.6033199771}
import axios from 'axios';

let baseUrl = 'https://dailyapi.zmjx.com/';
// if (window.document.domain === 'admin.zhimajx.com') {
//   baseUrl = 'https://api.zhimajx.com/';
// } else if (window.document.domain === 'localhost') {
//   baseUrl = 'https://devapi.zhimajx.com/';
// } else if (window.document.domain === 'devh5.zhimajx.com') {
//   baseUrl = 'https://devapi.zhimajx.com/';
// } else if (window.document.domain === 'grayh5.zhimajx.com') {
//   baseUrl = 'https://grayapi.zhimajx.com/';
// } else if (window.document.domain === 'dailyh5.zhimajx.com') {
//   baseUrl = 'https://dailyapi.zhimajx.com/';
// }

const baseReq = create();

function create(url = baseUrl) {
  return axios.create({
    baseURL: url,
    timeout: 100000,
    withCredentials: true, // 允许跨域 cookie
    transformResponse: [
      function (data) {
        let json = {};
        try {
          json = JSON.parse(data);
        } catch (e) {
          json = {};
        }
        return json;
      },
    ],
  });
}

baseReq.account = create(`/`);

// Add a request interceptor
baseReq.interceptors.request.use(function (config) {
  config.headers = {
    'X-Requested-With': 'XMLHttpRequest',
    token: 'a7ebc20ca70dc1836194deb40cfa31bd',
    userId: '1',
    zmjx_client: 4,
  };
  return config;
},
  function (error) {
    return Promise.reject(error);
  },
);

// Add a response interceptor
baseReq.interceptors.response.use(
  function (response) {
    if (response.data.responseCode === 100001) {
      window.localStorage.removeItem('user');
      setTimeout(() => {
        window.location.href = '#/user/login';
      }, 500);
    }
    return response.data;
  },
  function (error) {
    return Promise.reject(error);
  },
);

export default baseReq;
