Using Docker environment variables in an Angular2 application

I would like to use the predefined Docker Environment variable inside 'environment.prod.ts' from Angular-Cli (1.0.0-beta.16).

usecase:

environment.prod.ts:

export const environment = {
production: true,
host1: $ENV1, //specific service endpoint goes here
host2: $ENV2 //specific service endpoint goes here
};

my Angular CLI-based application depends on the .prod.ts environment for retrieving host information related to backend services (host1, host2), and the application goes through various environments such as DEV, TEST, QA, PROD ...

$ ENV1, $ ENV2 are provided as environment variables during Docker startup

Is it possible? If not, please correct my understanding and suggest any other alternative solutions.

+4
source share
1 answer

Angular - . , , , Docker. Docker ( ).

, :

... . <script> <html>:

<script>
var environment = { 
  host1: 'some injected value', 
  host2: 'depending on the view engine you are using' 
};
</script>

export interface Environment {
  host1: string;
  host2: string;
}

interface Window {
  environment: Environment;
}

API

... /

app.component.ts onInit() guard .

0

Source: https://habr.com/ru/post/1658336/


All Articles