mirror of
https://github.com/tenrok/axios.git
synced 2026-05-24 14:04:14 +03:00
ca42bb1d2a
In nodejs testing environment it's possible to use https://github.com/tmpvar/jsdom library to define a window object, but you still want to use node http adapter. Due to those diverse testing environmnents, I propose to test for XMLHttpRequest directly, because window global object is not a sure sign of a browser environment anymore.
27 lines
727 B
JavaScript
27 lines
727 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 (resolve, reject) {
|
|
try {
|
|
// For browsers use XHR adapter
|
|
if (typeof XMLHttpRequest !== 'undefined') {
|
|
require('../adapters/xhr')(resolve, reject, config);
|
|
}
|
|
// For node use HTTP adapter
|
|
else if (typeof process !== 'undefined') {
|
|
require('../adapters/http')(resolve, reject, config);
|
|
}
|
|
} catch (e) {
|
|
reject(e);
|
|
}
|
|
});
|
|
};
|
|
|