-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhttpCallsWrapper.js
50 lines (39 loc) · 1.04 KB
/
httpCallsWrapper.js
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
39
40
41
42
43
44
45
46
47
48
import { default as origAxios } from 'axios'
import { default as origFetch } from 'cross-fetch'
const URLSuffix = '' // '?Application=MyApplication
const formatURL = (url) => {
let q = '?'
if (URLSuffix !== "" && url.indexOf('?') > 0) {
q = '&'
url = url + q + URLSuffix.replace("?", "")
}
return url
}
//Wrapping Axios
export default function axios(args) {
let { url } = args
url = formatURL(url)
let arg = { ...args, url: url }
return origAxios(arg)
}
axios.get = (url, args) => {
url = formatURL(url)
return origAxios.get(url, args)
}
//========================
//Wraping fetch
export function (url, ...args) {
url = formatURL(url)
return fetch(url, ...args)
}
//========================
//Wrapping cross-fetch
export function crossFetch(url, ...args) {
url = formatURL(url)
return origFetch(url, ...args)
}
//==========================
//Usage:
//import {fetch} from './httpCallsWrapper'
//import {crossFetch} from './httpCallsWrapper'
//import {axios} from './httpCallsWrapper'