import axios from 'axios';
import Cookies from 'js-cookie'
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8';

const TokenKey = 'Admin-Token'
const service = axios.create({
  baseURL: '/dev-api',
  // baseURL: 'http://124.223.15.102:8888',
  timeout: 10000,
});
function getToken() {
  return Cookies.get(TokenKey)
}
service.interceptors.response.use((res) => {
  return res.data;
});
service.interceptors.request.use(config => {
  config.headers['Authorization'] = 'Bearer ' + getToken()
  return config
}, error => {
})

function request({ method = 'get', url, data = {}, params = {} }) {
  return service({
    method,
    url,
    data,
    params,
  });
}

export default request;
