Alexander Kim
Alexander Kim

Reputation: 18401

Nuxt environment variables in nuxt.config.ts

nuxt.config.ts:

env: {
  cmsUrl: process.env.CMS_URL || 'http://localhost:1337'
}

I'm setting CMS_URL as system variable on a production/staging mode, otherwise it would use a localhost in a dev mode.

However if i reuse this env variable inside nuxt.config.ts:

axios: {
  baseURL: process.env.cmsUrl
}

My NUXT app won't even start, saying ECONNREFUSED 127.0.0.1:80, i assume thats because env variable is not working.

Upvotes: 1

Views: 1796

Answers (1)

Alexander Kim
Alexander Kim

Reputation: 18401

The problem was in the stage, where i was applying environment variables, i was applying them in a docker-compose file, with npm run start command, and i built image one stage before with npm run build, that's why my env variables wasn't picked at all.

Upvotes: 0

Related Questions