Angular CLI Proxy setup

During development, you often end up in the situation where you have your backend API server running at one address (i.e. localhost:8080) while your frontend development server runs on another (i.e. localhost:4200).
First create proxy.config.json file

Then serve your app with proxy option by type this command:
ng serve –proxy-config proxy.config.json

ref: https://github.com/angular/angular-cli/wiki/stories-proxy

ref: Angular CLI commands reference: https://github.com/feloy/angular-cli-refcard/blob/master/angular-cli-refcard.pdf

 

If you work behind a corporate proxy, the regular backend proxy configuration will not work if you try to proxy calls to any URL outside your local network.

In this case, you can configure the backend proxy to redirect calls through your corporate proxy using an agent:

npm install --save-dev https-proxy-agent

Then instead of using a proxy.conf.json file, we create a file called proxy.conf.js with the content

ref: https://github.com/angular/angular-cli/wiki/stories-using-corporate-proxy

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s