In my current Angular 16 project, I am facing a unique scenario where each machine running the application locally has a different IP address. This means that the server URL will vary for each instance. Currently, I am retrieving this URL from the environment.ts
file as follows:
export const environment = {
apiUrl: 'http://11.22.33.44:5678/',
};
Every time I need to build the application, I have to manually change the URL. What I aim to achieve is a CLI command method for this purpose e.g.
ng build --configuration=production --serverUrl=http://55.66.77.88:5678/
.
Below is a snippet of my angular.json
configuration for the production environment:
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.development.ts",
"with": "src/environments/environment.ts"
}
]
}
I came across an article on Stack Overflow here, which suggests creating multiple environments but it doesn't provide a fully dynamic solution.