Tuesday, November 27, 2018

How to do proxy configuration in AngularJS project

1- In package.json change the start

"start": "ng serve --proxy-config proxyconfig.json",

2- Create one file called as proxyconfig.json

{
"/api":{
"target":"http://localhost:2303/",
"secure":false,
"changeOrigin":true
}
}

3- In serive now instead of calling whole url i.e. http://localhost:2303 use this one /api
return this.myHtpClient.get('/api');

4- do npm start or ng serve one more time

Note: If you see the chrome F12 network we will find the URL that is displayed to the end user is http://localhost:4200 rather than http://localhost:2303. This is the way we can do proxy configuration.

No comments: