I'm trying to build and deploy my angular 9 project in production environment. The main goal is to protect my back-end services IP address and credentials as these environments can't be exposed to anyone for security issue. Build and Serve works fine for current setups but the problem is i can't access/read environment variables except one that i created using shell. Only i can read the value of TEST1 variable but BASE_URL and NOTIFICATION_URL shows undefined. One important thing is that i have no idea about system OS environment variable and don't system environment will work in production build. I just googled and created those variables in shell and echo shows value properly but i'm not sure i'm in a proper way. Please Suggest me the suitable way or currently where i made mistake. And what about production?
Shell variables i created:
Custom Webpack
const webpack = require('webpack');
module.exports = {
plugins: [new webpack.DefinePlugin({
'process.env': {
BASE_URL: JSON.stringify(process.env.BASE_URL),
NOTIFICATION_URL: JSON.stringify(process.env.NOTIFICATION_URL),
TEST1: JSON.stringify(process.env.TEST1)
}
})]
}
typings.d.ts
// @ts-ignore
declare var process: Process;
interface Process {
env: Env
}
interface Env {
BASE_URL: string
NOTIFICATION_URL: string
TEST1: string
}
interface GlobalEnvironment{
process: Process;
}
environment.prod.ts
export const environment = {
production: true,
baseUrl: `${process.env.BASE_URL}`,
notificationUrl: `${process.env.NOTIFICATION_URL}`,
test: `${process.env.TEST1}`,
};