Angular CLI: Change REST API URL on build

后端 未结 7 1666
心在旅途
心在旅途 2021-02-02 08:58

I want to remove my local server prefix from my REST API URLs (example, http://localhost:8080) when building for production (ng build --prod).

I get that i

7条回答
  •  执笔经年
    2021-02-02 09:39

    You will find the URL configuration in environment.ts and environment.prod.ts file. Don't put hardcoded URL while calling the API. A good practice is to read the API URLs from environment.ts and environment.prod.ts file

    For the local environment use environment.ts

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

    For the production environment use environment.prod.ts

    export const environment = 
    {
        production: true,
        API_URL: 'http://api.productionurl.com',
    };
    

提交回复
热议问题