I have an Angular app where i'm trying to set the environment variable from outside of the app i.e., from docker compose file.
I'm referring below article
https://codinglatte.com/posts/angular/using-os-environment-variables-in-angular-with-docker/
docker-compose.yml
version: '3'
services:
tomcat-server:
image: "tomcat:latest"
ports:
- "8071:8080"
environment:
- API_URL=http://demo-production.com
I could even see the environment variable set when I execute the below command
docker exec -it <dockerName> sh
env
but somehow the value is not being received by Angular app, below is my Angular app code as per the above article
environment.prod.ts
export const environment = {
production: true,
API_URL: $ENV.API_URL,
TEST_ENV: 'testing'
// API_URL: 'http://production.com'
};
typings.d.ts
declare var $ENV: Env;
interface Env {
API_URL: string
}
custom-webpack.config.js
const webpack = require('webpack');
module.exports = {
plugins: [
new webpack.DefinePlugin({
$ENV: {
API_URL: JSON.stringify(process.env.API_URL)
}
})
]
};
Command I used to create the build
ng build --configuration=production --base-href=/demoapp/
I couldn't figure out the issue here as the environment value set in docker file is not reflecting in my app.
Can I get some help here?