简体   繁体   中英

Angular 8 : set production environment for api base url

Working on angular 8 project and I want to set two environments configuration, one for dev and other for prod :

dev

export const environment = {
  production: false,
  baseUrl: 'http://localhost:8000/api'
};

prod

export const environment = {
  production: true,
  baseUrl: 'https://serverurl/api/api'
};

the problem here is when I run npm run ng build --prod and test after that a register route on my api it doesn't work, on the other side it works when I test with postman !

Use the configuration option to build with the proper environment

ng build --prod --configuration=production

In your angular.json you should find something like this:

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

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