mirror of
https://github.com/axios/axios.git
synced 2026-04-15 15:36:19 +08:00
35 lines
946 B
JavaScript
35 lines
946 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 {
|
|
var adapter;
|
|
|
|
if (typeof config.adapter === 'function') {
|
|
// For custom adapter support
|
|
adapter = config.adapter;
|
|
} else if (typeof process !== 'undefined') {
|
|
// For node use HTTP adapter
|
|
adapter = require('../adapters/http');
|
|
} else if (typeof XMLHttpRequest !== 'undefined') {
|
|
// For browsers use XHR adapter
|
|
adapter = require('../adapters/xhr');
|
|
}
|
|
|
|
if (typeof adapter === 'function') {
|
|
adapter(resolve, reject, config);
|
|
}
|
|
} catch (e) {
|
|
reject(e);
|
|
}
|
|
});
|
|
};
|
|
|