import axios from axios const proxy axios create proxy CancelToken axi

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import axios from 'axios'
const proxy = axios.create({})
proxy.CancelToken = axios.CancelToken
proxy.isCancel = axios.isCancel
proxy.interceptors.request.use(
(config) => {
let token = VueCookie.get('logged_user_jwt', { domain: cookieDomain })
if (token) {
config.headers['Authorization'] = `Bearer ${token}`
}
return config
},
(error) => {
return Promise.reject(error)
}
)
export default proxy
let requests = []
function getProxyCancelToken (proxy) {
console.debug('removePendingRequest', proxy)
for (let i = 0; i < requests.length; i++) {
let remove = requests[i]
remove()
}
let cancel
let token = new proxy.CancelToken(function executor (c) { cancel = c })
requests.push(cancel)
return { cancelToken: token }
}
export { getProxyCancelToken }