frontend/src/helpers/http-common.js

17 lines
381 B
JavaScript
Raw Normal View History

2020-08-19 11:38:25 +00:00
import axios from 'axios';
import { API_URL } from '../constants';
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
// Add token if already in local storage
2020-08-22 20:49:03 +00:00
if (existingToken) {
backend.defaults.headers.common['Authorization'] = JSON.parse(existingToken);
2020-08-22 20:49:03 +00:00
}