Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Package nuxt app in different environment

I would like to run npm run generate with environment

for example:

package.json

"scripts": {
    "staging": "NODE_ENV=staging nuxt generate"
}

Generate a dist/ with staging environment using

npm run staging

then when requesting to an API I would like to determine what URL I'm going to use depends on the the environment I'm running

let baseURL = () => {
  switch (process.env.NODE_ENV) {
    case "it":
      return "https://example-url.com/it";
    case "staging":
      return "https://example-url.com/staging";
  }
};

const axiosClient = axios.create({
  baseURL: baseURL(),
  headers: {
    Accept: "application/json",
    "Content-Type": "application/json",
    "X-Api-Key": state().token
  }
});

the baseURL() should return the staging since I packaged the app in staging env

like image 961
AllenC Avatar asked Sep 03 '25 07:09

AllenC


1 Answers

When deploying my app to s3. I would like to deploy the code with environment attached so that the app knows which URL to call. I managed to do this by adding this in package.json

    "generate": "NUXT_ENV_STAGE=it nuxt generate",

According to this https://nuxtjs.org/api/configuration-env/#automatic-injection-of-environment-variables

like image 122
AllenC Avatar answered Sep 05 '25 01:09

AllenC