axios-axios/lib/core/dispatchRequest.js
2015-12-14 20:06:57 -07:00

26 lines
777 B
JavaScript

'use strict';
/**
* Dispatch a request to the server using whichever adapter
* is supported by the current environment.
*
* @param {object} config The config that is to be used for the request
* @returns {Promise} The Promise to be fulfilled
*/
module.exports = function dispatchRequest(config) {
return new Promise(function executor(resolve, reject) {
try {
if ((typeof XMLHttpRequest !== 'undefined') || (typeof ActiveXObject !== 'undefined')) {
// For browsers use XHR adapter
require('../adapters/xhr')(resolve, reject, config);
} else if (typeof process !== 'undefined') {
// For node use HTTP adapter
require('../adapters/http')(resolve, reject, config);
}
} catch (e) {
reject(e);
}
});
};