I have encountered a strange issue where defining
axios.defaults.baseURL = baseUrl;
results in an unexpected GET request right after initializing my Vue app. Any assistance would be greatly appreciated!
Below are images showing the code and network requests:
I attempted to follow the suggestions on Setting baseUrl for Axios in Vue js sends out request
Unfortunately, this solution did not work for me
import axios from 'axios';
export const baseUrl = 'http://imfood-core.local';
axios.defaults.baseURL = baseUrl;
axios.interceptors.request.use(function (request) {
if(request.url !== `/api/login_check`){
request.headers['Authorization'] = `Bearer ${localStorage.getItem('token')}`
}
return request;
}, function (error) {
return Promise.reject(error);
});
axios.interceptors.response.use(function (response) {
axios.defaults.baseURL = baseUrl;
return response;
}, function (error) {
if(error.response && error.response.status == 401 && error.config.url !== `${baseUrl}/api/login_check`){
localStorage.removeItem('token');
window.location.reload();
return Promise.reject(error);
}
return Promise.reject(error);
});
export default axios;
[1]: https://i.stack.imgur.com/6E9dD.png
[2]: https://i.stack.imgur.com/fnBST.png
[3]: https://i.stack.imgur.com/7sy5z.png