1

I have an API project and an Angular Project under the same solution in .NetCore. My angular project is calling the APIs from the API project. In order to access the APIs,i have put the baseurl of the API in the Environment.ts and Environment.prod.ts file. But after publishing the project i realized the Environment files are not created. Now for some reason the baseurl of the API got changed. How do i replace the new API url without publishing the Angular Project all over again.

Tony Ngo
  • 19,166
  • 4
  • 38
  • 60

2 Answers2

1

But after publishing the project i realized the Environment files are not created.

You wont see the env file because it's already bundle every everything into js file

There is not other way to do that without publishing your solution again.

You have to build everything again and again to update your code change there is no way way around.

Update: To import json into your angular app simply use require like this

const jsonData = require('/assets/appsetting.json');

You can view another answer here I wont go through it again because there are already an answer

Tony Ngo
  • 19,166
  • 4
  • 38
  • 60
0

Indeed, as you've noticed, the environments files are not available because they have been integrated into the built artifact. If you want to dynamically change the environments URL, you will have to code the logic: a service that fetch the API urls on some kind of server.

Usually, if it's just an environment URL to change, I find it is enough to just rebuild the site, as the rebuild is fairly quick.

Videl
  • 840
  • 2
  • 7
  • 18