Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 3651 | Rev 5245 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 3651 Rev 5244
Línea 1... Línea 1...
1
import Axios from "axios";
1
import Axios from 'axios'
Línea 2... Línea 2...
2
 
2
 
3
let axios = Axios.create({
3
const axios = Axios.create({
4
  baseURL: '',
4
  baseURL: ''
Línea 5... Línea 5...
5
});
5
})
6
 
6
 
7
axios.get = (_url, params = {}) => {
7
axios.get = (_url, params = {}) => {
8
  let url = _url
8
  let url = _url
9
  if (!_url.includes('t=')) {
-
 
10
    if (_url.includes('?'))
-
 
11
      url += '&'
-
 
12
    else
9
  if (!_url.includes('t=')) {
13
      url += '?'
10
    if (_url.includes('?')) { url += '&' } else { url += '?' }
14
    url += 't=' + new Date().getTime()
11
    url += 't=' + new Date().getTime()
15
  }
12
  }
16
  return Axios.get(url, {
13
  return Axios.get(url, {
17
    headers: {
14
    headers: {
18
      'Accept': 'application/json',
15
      Accept: 'application/json',
19
      'Vary': 'Accept',
16
      Vary: 'Accept',
20
      'Cache-Control': 'no-cache, no-store'
17
      'Cache-Control': 'no-cache, no-store'
21
    },
18
    },
22
    params
19
    params
Línea 23... Línea 20...
23
  });
20
  })
24
}
21
}
25
 
22
 
26
axios.all = Axios.all;
23
axios.all = Axios.all
27
axios.spread = Axios.spread;
24
axios.spread = Axios.spread
28
axios.upload = (url, data) => {
25
axios.upload = (url, data) => {
29
  return axios.post(url, new FormData(data), {
26
  return axios.post(url, new FormData(data), {
30
    headers: {
27
    headers: {
31
      'Content-Type': 'multipart/form-data'
28
      'Content-Type': 'multipart/form-data'
Línea 32... Línea 29...
32
    }
29
    }
33
  });
30
  })
34
}
31
}
35
 
32
 
36
axios.interceptors.request.use(
33
axios.interceptors.request.use(
37
  async (request) => {
34
  async (request) => {
38
    if (['post', 'put', 'delete'].includes(request.method)) {
35
    if (['post', 'put', 'delete'].includes(request.method)) {
Línea 39... Línea 36...
39
      try {
36
      try {
40
        const resp = await axios.get('/csrf')
37
        const resp = await axios.get('/csrf')
41
        if (resp.data.success) {
-
 
42
          request.headers['X-CSRF-TOKEN'] = resp.data.data
38
        if (resp.data.success) {
43
 
39
          request.headers['X-CSRF-TOKEN'] = resp.data.data
44
          return request;
40
 
45
        }
41
          return request
46
      }
42
        }
47
      catch (err) {
43
      } catch (err) {
48
        throw new Error(`Axios problem with request during pre-flight phase: ${err}.`);
44
        throw new Error(`Axios problem with request during pre-flight phase: ${err}.`)
49
      }
45
      }
50
    }
-
 
51
  },
-
 
52
  (error) => {
46
    }
-
 
47
  },
-
 
48
  (error) => {