-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigs.ts
39 lines (37 loc) · 970 Bytes
/
configs.ts
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
import { adapterXHR } from './adapters'
import { AxiosRequestConfig } from './typding'
import { isObject } from '../../javascript/lang/is/is'
import { setContentTypeIfNeed } from './helpers'
export const DEFAULT_HEADER_ACCEPT = {
Accept: 'application/json, text/plain, */*'
}
export const defaults: AxiosRequestConfig = {
url: '',
method: 'get',
headers: DEFAULT_HEADER_ACCEPT,
timeout: 0,
responseType: 'json',
transformRequestData: [
function transformRequest(data, headers) {
if (data instanceof FormData) {
return data
}
if (isObject(data)) {
setContentTypeIfNeed(headers, 'application/json;charset=utf-8')
return JSON.stringify(data)
}
return data
}
],
transformResponse: [
function transformResponse(data) {
if (typeof data === 'string') {
try {
return JSON.parse(data)
} catch (e) {}
}
return data
}
],
adapter: adapterXHR
}