简体   繁体   中英

How do I alter Environment .ts Variables or Constants Post Build In Angular 8, host URL and API URL?

I have this code in envrionment.ts

export const environment = {
    production: false,
    host_name: 'http://local.website.com',
    api_name: 'http://local.website.com/api',
    ajax_name: 'http://local.website.com/ajax',
};

Once the app is built, we need to change the environment settings without undergoing another build. Essentially because the web-app is coupled to another website, and the back-end people want to change these settings without running a build. Using the.env root file has been ruled-out as insecure leaving a.json file in the assets folder as the only option. There is another ts file on the app that can read the json with no problem when served but envrionment.ts can not seem to, supposedly because its static. Any help would be appreciated.

At the company I work for now, they adjust the settings via ftp. For this reason, it needs to read the json file and rewrite it every time the client is refreshed.

Follow the instructions in the url I shared. it worked for us.

https://christianlydemann.com/implementing-dynamic-environments-in-angular-for-avoiding-one-build-per-environment/

Edit : maybe you can use specifically created regex records. You can try changing it in main.bundle.js using the fs library belonging to nodejs. like this

export const environment = {
    production: '<<<<PRODUCTION>>>>',
    host_name: '<<<<HOST_NAME>>>>',
    api_name: '<<<<API_NAME>>>>',
    ajax_name: '<<<<AJAX_NAME>>>>',
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM