0

I'm using one file.json in asset's folder with my backend address file.json

{
    "api": "https://backend.com/api"
 }

then by a function I get the value from json:

 export const GET_API = function () {
         return require('../assets/file.json').api;
     };

but when I build the project by ng build --prod the value is static.

I'm looking one way to change the backend address on production

barbsan
  • 3,418
  • 11
  • 21
  • 28

1 Answers1

0

I'd suggest using server side rendering with angular universal. This will give you an opportunity to provide data derived from the request to the angular application.

The node service that serves the application can be setup to read it's configuration in any way you choose.

See https://angular.io/guide/universal - it's a bit of work up front but the most flexible way I've found to accomplish this kind of behaviour

Edit: as pointed out in a comment, if the only time you want this to change is between production and Dev builds then the environment files are a simple way to achieve this, but any change will require a rebuild which may not met your requirements - see https://angular.io/guide/build

Michael
  • 2,189
  • 16
  • 23