0

I have problem with axios interceptors. I try set header for jwt using interceptors but nothing work so I changed my code and added only console.log to this code. When I open console in Chrome nothing is displayed. Do you have any idea what the problem could be?

import axios from 'axios'
const baseURL = 'http://localhost:8080'
const instance = axios.create({
  baseURL,
  params: {}
})

instance.interceptors.request.use(function (config) {
    console.log('test');

     return config;
 }, function (error) {
     return Promise.reject(error)
 })

 export default instance
Stanisław Szewczyk
  • 105
  • 1
  • 3
  • 11
  • Does this answer your question? [Change the default base url for axios](https://stackoverflow.com/questions/47407564/change-the-default-base-url-for-axios) – Kamlesh Paul Sep 11 '20 at 10:30
  • I don't think so, I have problem with interceptors which not return console.log('test'); I haven't idea why? – Stanisław Szewczyk Sep 11 '20 at 10:44

1 Answers1

0

I just took a look into an old project that I used interceptors. There I called it directly on the axios object.

Perhaps something like the code bellow will work.

import axios from 'axios';

axios.defaults.baseURL = 'http://localhost:8080';

axios.interceptors.request.use(function (config) {
    
    console.log('config', config);

    return config;
}, function (error) {

    return Promise.reject(error)
});

export default instance;
Jonathan Martins
  • 734
  • 7
  • 24