Thursday, April 24, 2014

Cross Origin Resource Sharing with Node and Servlet

The book Pro AngularJS has a ToDo List application that I modified so that it gets its JSON model data from a Java servlet running on Tomcat hence, the servlet must set the CORS header to allow cross-origin resource sharing.

The HTML page is in the domain of the Node server. The request is made to the domain of the Java web app running on the Tomcat server with the URL on line 17 of the html file. The cross-site HTTP request requires the servlet set the Access-Control-Allow-Origin header which is done on line 21 of the JsonServlet.java file.