import axios from "axios";
// import { gettoken } from "../services/token";
// axios.defaults.withCredentials=true;
const instance = axios.create({
  baseURL: 'http://lhyt.zzly.vip:808', //请求的基础地址
  // baseURL: 'http://127.0.0.1:8000', //请求的基础地址
  timeout: 50000, //请求超时的时间
});
//发一个get请求

export const get = (url, params) => instance.get(url, { params });
//发一个post请求
export const post = (url, data) => instance.post(url, data);
export const put = (url, params) => instance.put(url, params);

export default instance;
// Add a request interceptor
//全局请求拦截，发起网络请求之前执行
instance.interceptors.request.use(

  function (config) {
    // Do something before request is sent
    // config.headers.Authorization = gettoken();
    return config;
  },
  (error) => {
    // Do something with request error
    return Promise.reject(error);
  }

);
// instance.interceptors.request((config) => {
//   return config
// })
// Add a response interceptor
//全局响应拦截，网络请求返回之后执行
instance.interceptors.response.use(
  function (response) {
    // Any status code that lie within the range of 2xx cause this function to trigger
    // Do something with response data
    return response.data;
  },
  function (error) {
    // Any status codes that falls outside the range of 2xx cause this function to trigger
    // Do something with response error
    return Promise.reject(error);
  }
);