123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- import axios from "axios";
- const token = localStorage.getItem("token");
- // const instance = axios.create({
- // baseURL: "https://test-app-a-level.herokuapp.com/api/",
- // headers: {
- // "Content-Type": "application/json",
- // Authorization: `Bearer ${token}`
- // }
- // });
- const AxiosInstance = axios.create({
- baseURL: "https://test-app-a-level.herokuapp.com/api/",
- headers: {
- "Content-Type": "application/json",
- Authorization: `Bearer ${token}`
- }
- });
- AxiosInstance.interceptors.request.use(
- config => {
- const token = localStorage.getItem("token");
- if (token) {
- return {
- ...config,
- headers: { ...config.headers, Authorization: `Bearer ${token}` }
- };
- }
- return config;
- },
- error => Promise.reject(error)
- );
- AxiosInstance.interceptors.response.use(
- response => response,
- error => {
- // const { response = {} } = error;
- // if (response.status === 403) logOut();
- return Promise.reject(error);
- }
- );
- // export default info => {
- // const { url, method = "GET", params, data } = info;
- // const result = AxiosInstance({ url, method, params, data });
- // return result;
- // };
- export default AxiosInstance;
|