Skip to content

Better support for runtime environment variables. #44184

@svenvandescheur

Description

@svenvandescheur

Describe the feature you'd like to request

When dealing with Docker based deployments on different environments, it's very useful to be able to specify environment variables for thinks like the base url for api calls, or a token for a analytics service.

Currently, it seems that next.js only properly supports specifying environment variables at build time, this leads to the following issue when using Docker.

  1. Build the docker image on CI with a specific (environment) configuration.
  2. Push the docker image to a repository.
  3. Pull/start the docker image on testing/staging/acceptance/production.
  4. Changing environment variables have no effect.

Describe the solution you'd like

I think there are type of environment variable that need to able to override:

  • Frontend specific configuration (tokens for services like analytics).
  • Backend/forntend configuration required for server side rendering the work correctly (api base url).

Being able to override the environment variables runtime would solve the first problem, but additional work on the server side render is probably also needed to support these cases properly.

Describe alternatives you've considered

An alternative would be to build specific Docker images for specific environments, however. I think this is considered an anti-pattern and should preferably be avoided.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions