Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Environment: How to make apiBaseUrl dynamic?

If my application is on production mode, I want the base URL of my API to be https://example.com/. If not, it should be http://localhost:8080/.

environment.prod.ts

export const environment = {
  production: true,
  apiBaseUrl: 'https://example.com/'
};

environment.ts

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

export const environment = {
  production: false,
  apiBaseUrl: 'http://localhost:8080/'
};

Now if I use environment in my service, it asks me to import either ../environment/environment or ../environments/environment.prod.

How can I make it to import the one which is needed? If production mode, import environment.prod, if not, import environment.

>Solution :

in angular.json you have this section

    "fileReplacements": [
            {
              "replace": "src/environments/environment.ts",
              "with": "src/environments/environment.prod.ts"
            }
          ],

this is doing the job for you

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading