BaseURL not being used
See original GitHub issueSummary
I’m having a problem with the defaults property. When an instance is created I’m setting the baseUrl, checking the defaults value I can see that the baseUrl has been set but once I try to send a single request axios is not using the baseUrl set previously.
Code used to request
const config = {
timeout: 1500,
baseUrl: 'https://reqres.in/api',
...defaults,
};
const instance = axios.create(config);
try {
const response = await instance.get('/users?page=2');
console.log(response);
} catch (e) {
console.error(e);
}
Note in the end of the response: _currentUrl: 'http:/users?page=2'
If I change the get method to have the full URL the request works.
Response
{
Error: connect ECONNREFUSED 127.0 .0 .1: 80
at TCPConnectWrap.afterConnect[as oncomplete](net.js: 1173: 14)
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 80,
config: {
adapter: [Function: httpAdapter],
transformRequest: {
'0': [Function: transformRequest]
},
transformResponse: {
'0': [Function: transformResponse]
},
timeout: 1500,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
validateStatus: [Function: validateStatus],
headers: {
Accept: 'application/json, text/plain, */*',
'User-Agent': 'axios/0.18.0'
},
method: 'get',
baseUrl: 'https://reqres.in/api',
url: '/users?page=2',
data: undefined
},
request: Writable {
_writableState: WritableState {
objectMode: false,
highWaterMark: 16384,
finalCalled: false,
needDrain: false,
ending: false,
ended: false,
finished: false,
destroyed: false,
decodeStrings: true,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: true,
bufferProcessing: false,
onwrite: [Function: bound onwrite],
writecb: null,
writelen: 0,
bufferedRequest: null,
lastBufferedRequest: null,
pendingcb: 0,
prefinished: false,
errorEmitted: false,
bufferedRequestCount: 0,
corkedRequestsFree: [Object]
},
writable: true,
_events: {
response: [Function: handleResponse],
error: [Function: handleRequestError]
},
_eventsCount: 2,
_maxListeners: undefined,
_options: {
protocol: 'http:',
maxRedirects: 21,
maxBodyLength: 10485760,
path: '/users?page=2',
method: 'get',
headers: [Object],
agent: undefined,
auth: undefined,
hostname: null,
port: null,
nativeProtocols: [Object],
pathname: '/users',
search: '?page=2'
},
_redirectCount: 0,
_requestBodyLength: 0,
_requestBodyBuffers: [],
_onNativeResponse: [Function],
_currentRequest: ClientRequest {
_events: [Object],
_eventsCount: 6,
_maxListeners: undefined,
output: [],
outputEncodings: [],
outputCallbacks: [],
outputSize: 0,
writable: true,
_last: true,
upgrading: false,
chunkedEncoding: false,
shouldKeepAlive: false,
useChunkedEncodingByDefault: false,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: 0,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
socket: [Socket],
connection: [Socket],
_header: 'GET /users?page=2 HTTP/1.1\r\nAccept: application/json, text/plain, */*\r\nUser-Agent: axios/0.18.0\r\nHost: localhost\r\nConnection: close\r\n\r\n',
_onPendingData: [Function: noopPendingOutput],
agent: [Agent],
socketPath: undefined,
timeout: undefined,
method: 'GET',
path: '/users?page=2',
_ended: false,
res: null,
aborted: undefined,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
_redirectable: [Circular],
[Symbol(isCorked)]: false,
[Symbol(outHeadersKey)]: [Object]
},
_currentUrl: 'http:/users?page=2'
},
response: undefined
}
Context
- axios version: 0.18.0
- Environment: node v9.9.0, chrome 65.0.3325.181, Mac OSX 10.13.4 (17E199)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:13
Top Results From Across the Web
Axios baseURL is not appending with the URL in react.js
It thinks you're passing an absolute URL (since the path '//users/register' starts with a double slash) and doesn't use the base URL. Share....
Read more >Accessing the ASP.NET Core Base URL: So Many Ways
NET Core Base URL Is Possible In a Number of Different Ways ... Fluxor is used for state management, and then in my...
Read more >Configuration - Cypress Documentation
This guide is for Cypress 10 and the new JavaScript configuration file format. If you are on an older version of Cypress that...
Read more >Request Config | Axios Docs
Only the url is required. Requests will default to GET if method is not specified. { // `url` is the server URL that...
Read more >Base URL not being used for thumbnails and other links
Base URL not being used for thumbnails and other links ... Ive installed jira software (server) on my centos machine. through nginx server...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Please, IGNORE THIS ISSUE. Found the problem:
I was setting
baseUrl
but it should bebaseURL
.well, probably there could be an alias of
baseUrl
tobaseURL