mirror of
https://github.com/tenrok/axios.git
synced 2026-05-30 15:24:11 +03:00
Adding baseURL to be used in getUri(), also removing question mark trimming since there seems to be no obvious reason for it. (#3737)
Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
+3
-1
@@ -5,6 +5,7 @@ var buildURL = require('../helpers/buildURL');
|
|||||||
var InterceptorManager = require('./InterceptorManager');
|
var InterceptorManager = require('./InterceptorManager');
|
||||||
var dispatchRequest = require('./dispatchRequest');
|
var dispatchRequest = require('./dispatchRequest');
|
||||||
var mergeConfig = require('./mergeConfig');
|
var mergeConfig = require('./mergeConfig');
|
||||||
|
var buildFullPath = require('./buildFullPath');
|
||||||
var validator = require('../helpers/validator');
|
var validator = require('../helpers/validator');
|
||||||
|
|
||||||
var validators = validator.validators;
|
var validators = validator.validators;
|
||||||
@@ -119,7 +120,8 @@ Axios.prototype.request = function request(configOrUrl, config) {
|
|||||||
|
|
||||||
Axios.prototype.getUri = function getUri(config) {
|
Axios.prototype.getUri = function getUri(config) {
|
||||||
config = mergeConfig(this.defaults, config);
|
config = mergeConfig(this.defaults, config);
|
||||||
return buildURL(config.url, config.params, config.paramsSerializer).replace(/^\?/, '');
|
var fullPath = buildFullPath(config.baseURL, config.url);
|
||||||
|
return buildURL(fullPath, config.params, config.paramsSerializer);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Provide aliases for supported request methods
|
// Provide aliases for supported request methods
|
||||||
|
|||||||
@@ -42,6 +42,10 @@ describe('static api', function () {
|
|||||||
expect(typeof axios.isCancel).toEqual('function');
|
expect(typeof axios.isCancel).toEqual('function');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should have getUri method', function() {
|
||||||
|
expect(typeof axios.getUri).toEqual('function');
|
||||||
|
});
|
||||||
|
|
||||||
it('should have isAxiosError properties', function () {
|
it('should have isAxiosError properties', function () {
|
||||||
expect(typeof axios.isAxiosError).toEqual('function');
|
expect(typeof axios.isAxiosError).toEqual('function');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ describe('instance', function () {
|
|||||||
'isCancel',
|
'isCancel',
|
||||||
'all',
|
'all',
|
||||||
'spread',
|
'spread',
|
||||||
|
'getUri',
|
||||||
'isAxiosError',
|
'isAxiosError',
|
||||||
'VERSION',
|
'VERSION',
|
||||||
'default'].indexOf(prop) > -1) {
|
'default'].indexOf(prop) > -1) {
|
||||||
@@ -112,4 +113,40 @@ describe('instance', function () {
|
|||||||
}, 100);
|
}, 100);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should have getUri on the instance', function() {
|
||||||
|
var instance = axios.create({
|
||||||
|
baseURL: 'https://api.example.com'
|
||||||
|
});
|
||||||
|
var options = {
|
||||||
|
url: 'foo/bar',
|
||||||
|
params: {
|
||||||
|
name: 'axios'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
expect(instance.getUri(options)).toBe('https://api.example.com/foo/bar?name=axios');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should correctly build url without baseURL', function () {
|
||||||
|
var instance = axios.create();
|
||||||
|
var options = {
|
||||||
|
url: 'foo/bar?foo=bar',
|
||||||
|
params: {
|
||||||
|
name: 'axios'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
expect(instance.getUri(options)).toBe('foo/bar?foo=bar&name=axios');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should correctly discard url hash mark', function () {
|
||||||
|
var instance = axios.create();
|
||||||
|
var options = {
|
||||||
|
baseURL: 'https://api.example.com',
|
||||||
|
url: 'foo/bar?foo=bar#hash',
|
||||||
|
params: {
|
||||||
|
name: 'axios'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
expect(instance.getUri(options)).toBe('https://api.example.com/foo/bar?foo=bar&name=axios');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user