text: import axios from 'axios';
  /*
  let baseURL = `http://${window.location.hostname}:8000/api/`; */
  let baseURL;
  if (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1') {
    baseURL = `http://${window.location.hostname}:8000/api/`;
  } else {
    baseURL = 'https://auroracomputing.herokuapp.com/api/';
  }
  
  const axiosInstance = axios.create({
    baseURL,
    timeout: 5000,
    headers: {
      Authorization: localStorage.getItem('access_token') ? `JWT ${localStorage.getItem('access_token')}` : null,
      'Content-Type': 'application/json',
      accept: 'application/json'
    }
  });
  
  axiosInstance.interceptors.response.use(
    (response) => response,
    async (error) => {
      const originalRequest = error.config;
  
      if (typeof error.response === 'undefined') {
        alert('A server/network error occurred. Looks like CORS might be the problem. Sorry about this - we will get it fixed shortly.');
        return Promise.reject(error);
      }
  
      if (error.response.status === 401 && originalRequest.url === `${baseURL}token/refresh/`) {
        window.location.href = '/login/';
        return Promise.reject(error);
      }
  
      if (error.response.data.code === 'token_not_valid' && error.response.status === 401 && error.response.statusText === 'Unauthorized') {
        const refreshToken = localStorage.getItem('refresh_token');
  
        if (refreshToken) {
          const tokenParts = JSON.parse(atob(refreshToken.split('.')[1]));
  
          // exp date in token is expressed in seconds, while now() returns milliseconds:
          const now = Math.ceil(Date.now() / 1000);
          console.log(tokenParts.exp);
  
          if (tokenParts.exp > now) {
            console.log('--- refresh ---');
            /* return axiosInstance
                              .post('/token/refresh/', { refresh: refreshToken })
                              .then((response) => {
                                  localStorage.setItem('access_token', response.data.access);
                                  localStorage.setItem('refresh_token', response.data.refresh);
  
                                  axiosInstance.defaults.headers['Authorization'] =
                                      'JWT ' + response.data.access;
                                  originalRequest.headers['Authorization'] =
                                      'JWT ' + response.data.access;
  
                                  return axiosInstance(originalRequest);
                              })
                              .catch((err) => {
                                  console.log(err);
                              }); */
          } else {
            console.log('Refresh token is expired', tokenParts.exp, now);
            localStorage.removeItem('access_token');
            localStorage.removeItem('refresh_token');
            axiosInstance.defaults.headers.Authorization = null;
            window.location.href = '/';
          }
        } else {
          console.log('Refresh token not available.');
          window.location.href = '/login/';
        }
      }
  
      // specific error handling done elsewhere
      return Promise.reject(error);
    }
  );
  
  export default axiosInstance;
  