mirror of
https://github.com/axios/axios.git
synced 2026-04-12 14:41:55 +08: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:
parent
195c8e5ff5
commit
bdb7d76d40
@ -5,6 +5,7 @@ var buildURL = require('../helpers/buildURL');
|
||||
var InterceptorManager = require('./InterceptorManager');
|
||||
var dispatchRequest = require('./dispatchRequest');
|
||||
var mergeConfig = require('./mergeConfig');
|
||||
var buildFullPath = require('./buildFullPath');
|
||||
var validator = require('../helpers/validator');
|
||||
|
||||
var validators = validator.validators;
|
||||
@ -119,7 +120,8 @@ Axios.prototype.request = function request(configOrUrl, config) {
|
||||
|
||||
Axios.prototype.getUri = function getUri(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
|
||||
|
||||
@ -42,6 +42,10 @@ describe('static api', 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 () {
|
||||
expect(typeof axios.isAxiosError).toEqual('function');
|
||||
});
|
||||
|
||||
@ -19,6 +19,7 @@ describe('instance', function () {
|
||||
'isCancel',
|
||||
'all',
|
||||
'spread',
|
||||
'getUri',
|
||||
'isAxiosError',
|
||||
'VERSION',
|
||||
'default'].indexOf(prop) > -1) {
|
||||
@ -112,4 +113,40 @@ describe('instance', function () {
|
||||
}, 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');
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user