Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set config using env vars #46

Open
subvind opened this issue Oct 10, 2021 · 1 comment
Open

set config using env vars #46

subvind opened this issue Oct 10, 2021 · 1 comment

Comments

@subvind
Copy link

subvind commented Oct 10, 2021

Hello, thank you for making vendure open source.

Lately I have been trying to get vendure to deploy on kubernetes and I feel so close to complete. My question has todo with the configuration of "storefront" and how we must do this with a environment.docker.ts file.

I am only familiar with old angular ... like 1.7 so I am a little rusty here. Does this file run on the server or does it get compiled to the browser and run there? I ask: because I am trying to get all of my settings to pass through ENV VARS.

export const environment = {
  production: true,
  apiHost: process.env.API_HOST || 'https://demo.vendure.io',
  apiPort: process.env.API_PORT || 443,
  shopApiPath: process.env.SHOP_API_PATH || 'shop-api',
  baseHref: process.env.BASE_HREF || '/storefront/',
  tokenMethod: 'bearer',
};

Dockerfile:

COPY environment.docker.ts ./src/environments

error: on the browser it says: "Uncaught ReferenceError: process is not defined at Object.62242 (main.a5b3c721c9edb633524b.js:1)"

This makes me believe every vendure app that I want to deploy needs to have a hard coded "environment.docker.ts" within the docker image build. So if I want to deploy 4 apps then I must build 4 separate docker images each with their own unique config file ... Please tell me this is not true.

@michaelbromley
Copy link
Member

Hi,

yes, your understanding of the environment.ts file is correct - it is compiled at build-time and is typically executed in the browser, so the env vars will not work like that.

A pattern I have successfully used in this case is described in this blog post - with an APP_INITIALIZER provider which fetches the correct environment data before the app bootstraps in the browser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants