'How to get env from docker container in nuxtjs

How to get env in nuxt.config.js, what should i write here?

Variables from the .env file come to the container, but nuxjs does not see them, I tried to get them like this instruction https://nuxtjs.org/tutorials/moving-from-nuxtjs-dotenv-to-runtime-config/

export default {
    server: {
        port: 3000, // default: 3000
    },

    ...

    publicRuntimeConfig: {
        apiUrl: process.env.API_URL || 'localhost',
    },

    apollo: {
        clientConfigs: {
            default: {
            httpEndpoint: apiUrl, <<-- how to get the value????????
                 prefetch: false,
            },
        },
    },
}

process.env.API_URL is a dynamic value that is substituted when starting a container via docker-compose



Solution 1:[1]

  1. I think You can't access this & this.$config within nuxt.config as it's usable in *.vue files.
    It's for use within your app itself. In the case you have, @nuxtjs/apollo would also have to have support for publicRuntimeConfig (I'm not sure if it does), and you would need unlucky to use process.env like so:
apollo: {
  clientConfigs: {
    default: {
      httpEndpoint: process.env.API_URL
    }
  }
}
  1. But there's an option! You can provide additional plugin to extend Apollo config which will have access to $config and then You can use it inside nuxt.config.js.

There is also closed FR Using runtime config in the nuxt.config.js #8635 on GH

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1