Answer the question
In order to leave comments, you need to log in
How to correctly set axios.baseUrl in Nuxt, what would work on both local and domain?
Good afternoon! Initially it was like this:
axios: {
baseURL: process.env.NODE_ENV === 'production'
? 'https://site-name.ru'
: 'http://localhost:3000'
},
axios: {
baseURL: '/'
},
async nuxtServerInit({ dispatch, getters, commit }) {
const isUserSigned = await dispatch('auth/autoSignin');
if (isUserSigned) await dispatch('auth/getUserByToken');
}
async getUserByToken({commit, dispatch}) {
try {
const user = await this.$axios.$get('/api/auth/getUserByToken');
if (user && user.id) {
dispatch('setUser', user);
} else {
dispatch('signout', false);
}
} catch (e) {
console.log(e.message);
dispatch('setUser', null);
dispatch('signout', false);
}
},
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question