Issue
I am trying to create angular 2 project. In my project I am going to use REST calls to Spring Boot microservice for database insertions and updations.
- I am using separate editor for creating Angular 2 project. I may choose sublime editor. My Spring Boot project is in STS editor. When I run the Angular 2 project on browser, It will call the REST point already started in STS editor?
- Both are in my local system. My Angular using localhost://4200 and my Spring Boot project is through localhost:8080/. So am I able to run the Angular project? this method is possible?
Solution
Yes, you will have to make the api calls using a CORS requests. For your endpoint just specify the full url http://localhost:8080/api when making request, and when in production just use the same origin /api. You would probably want use Spring to serve the contents of your dist folder for prod. You just need to figure out how to set a variable which you can check against for the environment so you can switch out the url.
For the dev api you will need to make sure CORS is configured correctly i.e handles OPTION request and sets the correct headers or browsers will complain.
Answered By - rtn
Answer Checked By - Candace Johnson (JavaFixing Volunteer)