This website collects cookies to deliver better user experience
The idea is to use Angular’s environment.ts (for local development) and environment.prod.ts (for all other stages) with placeholder values which are overwritten per deployment:
export const environment = { apiUrl: 'MY_APP_API_URL', stage: 'MY_APP_STAGE', };
If our pod is started we can then run the following script, for example in a Dockerfile, that overrides these placeholder values:
#!/bin/sh # replace placeholder value in JS bundle with environment specific values sed -i "s#MY_APP_API_URL#$API_URL#g" /usr/share/nginx/html/main.*.js
FROM nginx:latest COPY dist/your-app-name /usr/share/nginx/html CMD ["/bin/bash", "-c", \ "echo API_URL=[$API_URL], && \ sed -i s#MY_APP_API_URL#$API_URL#g /usr/share/nginx/html/main.*.js && \ nginx -g 'daemon off;'"]
$ ng build
$ docker build -t angular/your-app-name .
API_URL
$ docker run -p 80:80 --name your-app-name -e API_URL=http://localhost:8080 angular/your-app-name
41
0