7

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 }); 
4

2 Answers 2

12

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

Sign up to request clarification or add additional context in comments.

Comments

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" 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.