2020-08-19 11:38:25 +00:00
|
|
|
import axios from 'axios';
|
|
|
|
import { API_URL } from '../constants';
|
|
|
|
|
2020-08-26 18:13:12 +00:00
|
|
|
const existingToken = localStorage.getItem('token');
|
2020-08-22 20:49:03 +00:00
|
|
|
|
2020-08-19 11:38:25 +00:00
|
|
|
export const backend = axios.create({
|
|
|
|
baseURL: API_URL,
|
|
|
|
headers: {
|
|
|
|
'Content-type': 'application/json',
|
|
|
|
},
|
|
|
|
});
|
2020-08-22 20:49:03 +00:00
|
|
|
|
2020-09-02 21:08:41 +00:00
|
|
|
// Add token if already in local storage
|
2020-08-22 20:49:03 +00:00
|
|
|
if (existingToken) {
|
2020-08-26 18:13:12 +00:00
|
|
|
backend.defaults.headers.common['Authorization'] = JSON.parse(existingToken);
|
2020-08-22 20:49:03 +00:00
|
|
|
}
|