Home
Support Forums

My request url have undefined but I not set it. Please help me

I already setup environment var. but request url have undefined I don’t understand why.
image

My code is.

async getProject(): Promise {
try {
const res = await this.$axios.$get(
${process.env.IME_ENDPOINT}/api/project
)
if (res.success) {
this.project = res.data
}
} catch (error) {}
}

My .env file

NODE_ENV=development
IME_ENDPOINT=https://ime-database.herokuapp.com

PS. I use nuxt js with SPA

I’m seeing 3 problems:

  1. I think this is your client-side code, correct? ENV vars in NuxtJS should probably be used like: process.env.NUXT_ENV_IME_ENDPOINT. Basically, you need to prefix the variable as NUXT_ENV_ and the same should happen in UI, that is the variable should be saved as NUXT_ENV_IME_ENDPOINT. It’s only needed for automatic import of the variables, but if you’re using something like dotenv, this won’t be needed.

  2. Using ENV vars in client-side code, that too to hide a URL is not as useful as you’d expect. I mean, the variable is replaced by the actual value during build time, so anyone can see your site’s code and get the URL. Apart from that, they can still open the network tools like you did and get the URL, so it’s not really adding security.

  3. Your variable has the value https://ime-database.herokuapp.com and the Request URL is showing undefined after that value which makes me think you’re trying to add something after that variable which is not working. The code that you’ve shared doesn’t show the problem, but there’s definitely something else happening.