项目原始demo,不改动
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
Tento repozitář je archivovaný. Můžete prohlížet soubory, klonovat, ale nemůžete nahrávat a vytvářet nové úkoly a požadavky na natažení.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. 'use strict';
  2. var utils = require('./../utils');
  3. var buildURL = require('../helpers/buildURL');
  4. var InterceptorManager = require('./InterceptorManager');
  5. var dispatchRequest = require('./dispatchRequest');
  6. var mergeConfig = require('./mergeConfig');
  7. /**
  8. * Create a new instance of Axios
  9. *
  10. * @param {Object} instanceConfig The default config for the instance
  11. */
  12. function Axios(instanceConfig) {
  13. this.defaults = instanceConfig;
  14. this.interceptors = {
  15. request: new InterceptorManager(),
  16. response: new InterceptorManager()
  17. };
  18. }
  19. /**
  20. * Dispatch a request
  21. *
  22. * @param {Object} config The config specific for this request (merged with this.defaults)
  23. */
  24. Axios.prototype.request = function request(config) {
  25. /*eslint no-param-reassign:0*/
  26. // Allow for axios('example/url'[, config]) a la fetch API
  27. if (typeof config === 'string') {
  28. config = arguments[1] || {};
  29. config.url = arguments[0];
  30. } else {
  31. config = config || {};
  32. }
  33. config = mergeConfig(this.defaults, config);
  34. config.method = config.method ? config.method.toLowerCase() : 'get';
  35. // Hook up interceptors middleware
  36. var chain = [dispatchRequest, undefined];
  37. var promise = Promise.resolve(config);
  38. this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
  39. chain.unshift(interceptor.fulfilled, interceptor.rejected);
  40. });
  41. this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
  42. chain.push(interceptor.fulfilled, interceptor.rejected);
  43. });
  44. while (chain.length) {
  45. promise = promise.then(chain.shift(), chain.shift());
  46. }
  47. return promise;
  48. };
  49. Axios.prototype.getUri = function getUri(config) {
  50. config = mergeConfig(this.defaults, config);
  51. return buildURL(config.url, config.params, config.paramsSerializer).replace(/^\?/, '');
  52. };
  53. // Provide aliases for supported request methods
  54. utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) {
  55. /*eslint func-names:0*/
  56. Axios.prototype[method] = function(url, config) {
  57. return this.request(utils.merge(config || {}, {
  58. method: method,
  59. url: url
  60. }));
  61. };
  62. });
  63. utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
  64. /*eslint func-names:0*/
  65. Axios.prototype[method] = function(url, data, config) {
  66. return this.request(utils.merge(config || {}, {
  67. method: method,
  68. url: url,
  69. data: data
  70. }));
  71. };
  72. });
  73. module.exports = Axios;