In this section, you will learn about appropriate configuration that needs to be done in order to have Angular app invoke Spring RESTful APIs.
In the previous chapters, you learned how to run Angular and Spring apps on different servers which can be accessed using different URLs. An Angular app, when started with the ng serve --open
command, runs on port 4200
and can be accessed using a URL such as http://localhost:4200
. On the other hand, a Spring web app runs on a different port such as 8080
and can be accessed using a URL such as http://localhost:8080
. These apps, therefore, have different origins. Note that origin is combination of protocol, hostname, and the port number. As per the same origin policy, web browsers block XML HTTP Request (XHR) calls to a remote server whose origin is different from the origin of the web page. Due to this, any attempt to access Spring web/RESTful APIs from Angular apps would result in an error such as Access-Control-Allow...