import axios from 'axios'
import qs from 'qs'
// import router from '../router'

axios.defaults.baseURL = import.meta.env.VITE_BASE_URL;
axios.defaults.timeout = 8000;
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
axios.defaults.headers.get['Content-Type'] = 'application/x-www-form-urlencoded';

axios.interceptors.request.use(function (config) {
    if(config.method === 'get' && config.data) {
      config.data = qs.stringify(config.data)
    }
    if(config.method === 'post' && config.data) {
      config.data = qs.stringify(config.data)
    }
    return config;
  }, function (error) {
    return Promise.reject(error);
  });

axios.interceptors.response.use(function (response) {
    return response;
  }, function (error) {
    return Promise.reject(error);
  });

export default axios