I'm trying to create a wrapper for axios, so I can always use the same configuration.
The following works as expected:
function getAxiosInstance() {
const config = {
timeout: 3000,
headers: {
'Content-Type': 'application/json',
},
};
return axios.create(config);
}
getAxiosInstance().get('/foo');
However, just adding baseURL: 'http://localhost:8080/api/' to the configuration (i.e. config) results in two weird requests: The first without any request method and the second one has a method of type OPTIONS.
I tried omitting the domain and port (/api/) which surprisingly worked, but that's not what I'm trying to achieve.
I'm using the latest version of axios (0.21.0) although I tried with an earlier one as well.