{"size": 1456, "ext": "js", "max_stars_repo_path": "Frontend/timesheet-app/src/index.js", "max_stars_repo_name": "tjfy1992/GroupProjectTwo", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Frontend/timesheet-app/src/index.js", "max_issues_repo_name": "tjfy1992/GroupProjectTwo", "max_issues_repo_issues_event_min_datetime": "2021-07-03T22:03:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-03T22:03:43.000Z", "max_forks_repo_path": "Frontend/timesheet-app/src/index.js", "max_forks_repo_name": "tjfy1992/GroupProjectTwo", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 22.4, "max_line_length": 79, "alphanum_fraction": 0.6325549451}
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import axios from 'axios';
import qs from 'qs';


//axios interceptor for request
axios.interceptors.request.use(

  (config) => {
    let token = localStorage.getItem('token')
    if(token){
      config.headers['token'] = token;
    }
    else{
      config.headers['token'] = '';
    }

    if (config.method === "post"){
        if(config.headers['Content-Type'] !== 'multipart/form-data'){
          config.data = qs.stringify(config.data);
          config.headers['Content-Type'] = 'application/x-www-form-urlencoded';
        }  
    }
    return config;
  },

  (req) => {
     return req;
  },

  (err) => {
     return Promise.reject(err);
  }
);

//axios interceptor for response
axios.interceptors.response.use(
  (successRes) =>  {
    return successRes;
  }, 
  (error) => {
    if(error.response.status === 403){
      localStorage.clear()
      window.location.href = 'http://localhost:3000'
    }
    return Promise.reject(error);
  }
);

ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
  document.getElementById('root')
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
