|
@@ -10,21 +10,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
import Axios from 'axios';
|
|
|
import qs from 'querystring';
|
|
|
const factory = (opts) => {
|
|
|
- const { baseURL, notifier, bridge, withCredentials = true } = opts || {};
|
|
|
+ const { baseURL, notifier, bridge, withCredentials = true, defaultDataType = 'form' } = opts || {};
|
|
|
const axios = Axios.create({
|
|
|
baseURL,
|
|
|
withCredentials
|
|
|
});
|
|
|
return (opts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
- const { url, method, query, data, dataType = 'form', headers = {} } = opts;
|
|
|
+ const { url, method, query, data, dataType = defaultDataType, headers = {} } = opts;
|
|
|
let contentType;
|
|
|
+ let formattedData;
|
|
|
if (dataType === 'form') {
|
|
|
contentType = 'application/x-www-form-urlencoded';
|
|
|
+ formattedData = data && qs.stringify(data);
|
|
|
}
|
|
|
else if (dataType === 'json') {
|
|
|
contentType = 'application/json';
|
|
|
+ formattedData = data && JSON.stringify(data);
|
|
|
}
|
|
|
- if (method === 'POST') {
|
|
|
+ if (method === 'POST' && contentType) {
|
|
|
Object.assign(headers, {
|
|
|
'Content-Type': contentType
|
|
|
});
|
|
@@ -36,7 +39,7 @@ const factory = (opts) => {
|
|
|
method,
|
|
|
params: query,
|
|
|
headers,
|
|
|
- data: data && (dataType === 'form' ? qs.stringify(data) : JSON.stringify(data))
|
|
|
+ data: formattedData
|
|
|
});
|
|
|
}
|
|
|
catch (e) {
|