axios-module icon indicating copy to clipboard operation
axios-module copied to clipboard

Does this package support setting multiple baseURLs?

Open cssagogo opened this issue 5 years ago • 1 comments

I have 2-3 primary API sources I'm hitting.

Firebase Firebase Auth 3rd Party Data Provider

Is there a way to set this up in Nuxt?

cssagogo avatar Sep 24 '20 22:09 cssagogo

Hey, Sorry for the late response. You can't set multiple baseURLs, but there is solution for your situation. You can create two different instances of axios based on your configurations. Checkout module docs to find more

Create a plugin and inject your new instances:

export default function ({ $axios }, inject) {
  // Create a custom axios instance
  const firebase = $axios.create({
    headers: {
      common: {
        Accept: 'text/plain, */*'
      }
    }
  })

  // Set baseURL to something different
  firebase.setBaseURL('https://firebase')
  // Inject to context as $firebase
  inject('firebase', firebase)


 const firebaseAuth = $axios.create({
    headers: {
      common: {
        Accept: 'text/plain, */*'
      }
    }
  })

  // Set baseURL to something different
  firebaseAuth.setBaseURL('https://firebase-auth')
  // Inject to context as $firebaseAuth
  inject('firebaseAuth', firebaseAuth)
}

farnabaz avatar Feb 03 '21 12:02 farnabaz