1

I have deployed a Vue.js application to heroku an api also hosted on heroku.

The VueJS app uses axios to connect to the api. I have set a config variable in heroku:

VUE_APP_ROOT_API = https://[my-express-api].herokuapp.com/api

Here is my base axios call:

import axios from 'axios'
const token = localStorage.getItem('token')

export default () => {
  console.log(process.env.VUE_APP_ROOT_API)
  return axios.create({
    baseURL: process.env.VUE_APP_ROOT_API,
    headers: {
      'Content-Type': 'application/json',
      token: token,
    },
    validateStatus: function () {
      return true;
    }
  })
}

However, the console log reveals that the variable is undefined and axios is using the Vue app url as the base for api calls (https://[my-vue-app].herokuapp.com/undefined/) instead of the one specified in the config variable.

2 Answers 2

2

Resolved this. It turns out that my config variable was being compiled into the code at build time, so once I deployed to trigger a rebuild, the new config var worked. Adding/Updating config vars will automatically restart the dynos, but that doesn't rebuild any compiled code.

Sign up to request clarification or add additional context in comments.

Comments

0

For me, appending the build command in my package.json with '--mode production' before pushing to heroku fixed the issue.

https://forum.vuejs.org/t/production-env-on-app-deployed-in-heroku/71077

Good luck!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.