Rev 7400 | AutorÃa | Comparar con el anterior | Ultima modificación | Ver Log |
import Axios from 'axios'export const cancelToken = Axios.CancelToken.source()const axiosInstance = Axios.create()axiosInstance.all = Axios.allaxiosInstance.spread = Axios.spreadaxiosInstance.upload = (url, data) => {return axiosInstance.post(url, new FormData(data), {headers: {'Content-Type': 'multipart/form-data',},})}axiosInstance.interceptors.request.use(async (request) => {request.baseURL = 'https://dev-services.leaderslinked.com'if (['post', 'put', 'delete'].includes(request.method)) {try {const resp = await axiosInstance.get('/csrf')if (resp.data.success) {request.headers['X-CSRF-TOKEN'] = resp.data.datareturn request}} catch (err) {throw new Error(`Axios problem with request during pre-flight phase: ${err}.`)}}},(error) => {return Promise.reject(error)})axiosInstance.get = (_url, params = {}) => {let url = _urlif (!_url.includes('t=')) {if (_url.includes('?')) {url += '&'} else {url += '?'}url += 't=' + new Date().getTime()}return Axios({method: 'GET',baseURL: 'https://dev-services.leaderslinked.com',url,params,headers: {Accept: 'application/json',Vary: 'Accept','Cache-Control': 'no-cache, no-store',},})}export default axiosInstance