2

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 !

4
  • You have 2 api in here : https://serverurl/api/api Commented Sep 16, 2019 at 15:41
  • What is the error you are getting Commented Sep 16, 2019 at 15:41
  • @AdritaSharma that's not the real problem, it works when test with any api test tools, because the folder name is api on the server and api prefix is api also, Commented Sep 16, 2019 at 15:47
  • @AdritaSharma I didn't get any error, a 200 response!! and I didn't find any row on my database :/ Commented Sep 16, 2019 at 15:48

1 Answer 1

6

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"
          }
        ],
...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.