I am trying to connect a small angular app to my rest webservice written in spring. My tomcat server is running on localhost:8080 and my grunt server is running on localhost:11000. This causes CORS errors in the console and I cannot make requests from my browser to the rest API.
I have spent all morning going through pretty much post I can find online and I still cannot get this working, I am able to get my pages served to me now as some examples even stop this from working. I do see console logging in the cmd window that the grunt server is writing to but no matter what I have tried I just keep getting the CORS error:
connect: {
livereload: {
options: {
port: 11000,
hostname: 'localhost',
open: false,
middleware: function(connect, options, middlewares) {
middlewares.unshift(function(req, res, next) {
console.log('***** ADDING HEADERS *****');
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Credentials', true);
res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.setHeader('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
next();
});
return middlewares;
}
}
}
}
Is anyone able to tell me how I can get around this problem?