6

I have Angular project which I would like to deploy on Apache server. I use ng build but I would like to custom address and endpoint for backend.

proxy.conf.json:

{
  "/api/*": {
    "target": "http://localhost:8080",
    "secure": false,
    "logLevel": "debug",
    "changeOrigin": true
  }
}

This configuration is not applied at all. How I can set it properly in order to change configurations?

Environment ts file:

import {environment as prod} from './environment.prod';

export const environment = Object.assign(prod, {
  production: false
});
veben
  • 19,637
  • 14
  • 60
  • 80
Peter Penzov
  • 1,126
  • 134
  • 430
  • 808

2 Answers2

11

You can define different environment files. Below example for "dev":

export const environment = {
    production: false,
    envName: 'dev',
    configPath: './assets/config/config.dev.json'
    ...
};

Add a configuration part for "dev" in "angular.json" file, like that:

"dev": {
  "fileReplacements": [
    {
      "replace": "src/environments/environment.ts",
      "with": "src/environments/environment.dev.ts"
    }
  ],
  ....

And use this command to build : ng build --configuration=dev

For more information, take a look at this post : How to set environment via `ng serve` in Angular 6

veben
  • 19,637
  • 14
  • 60
  • 80
2

Assuming you are using Angular (>v6), and you have created multiple environment files as per requirements.

So what you need to do is, go to angular.json file

angular.json > projects > projectName > architect > build > configurations > fileReplacements

and here you need to replace files name with your files name like this -

"replace": "src/environments/environment.ts",
"with": "src/environments/environment.live.ts"
Pardeep Jain
  • 84,110
  • 37
  • 165
  • 215