Files
praesentation-source/src/libs/api.js
2021-03-18 10:59:46 +01:00

29 lines
812 B
JavaScript

import Axios from "axios";
export default () => {
// var token = document.getElementsByName("csrf-token")[0].getAttribute(
// "content",
// );
const AxiosInstance = Axios.create({
baseURL: "https://random-data-api.com/api/",
// withCredentials: true,
headers: {
"Content-Type": "application/json",
"Credentials": "same-origin",
"Accept": "application/json",
// "X-CSRF-Token": token,
},
});
AxiosInstance.interceptors.response.use((response) => {
return response;
}, function (error) {
// console.log('Axios interceptor ....')
if (error.response.status === 401) {
// console.log('unauthorized, logging out ...')
window.document.location.href = "/";
}
return Promise.reject(error.response);
});
return AxiosInstance;
};