0

I am using node.js server to consume rest resource from angular js application.

My angular application is running on port 8082 and rest resource available at port 9081. I am able to access rest resource but get CORS exception in developer console.

I find out the solution to get rid of CORS exception. I have used jsonp instead of get method in angular service also got response without any exception, but unable to perform operation on the data return with response.

I come to know that I have to use http-proxy to communicate cross domain applications. If it is right can you please suggest me how can I configure http-proxy in node.js server.

4
  • Did you configure cors settings on spring-mvc side? Commented Mar 15, 2017 at 5:17
  • Try adding middle ware code to allow access. app.all('/*', function(req, res, next) { res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Allow-Headers", "X-Requested-With, Content-Type"); res.header("Access-Control-Allow-Methods", "GET, POST","PUT"); next(); }); Commented Mar 15, 2017 at 6:00
  • @Anil Kumar You can use the package cors Its a middleware which can be used to enable the cors with various options. Commented Mar 15, 2017 at 7:20
  • Thanks All. I have tried above suggestions (using cors in node.js and set header to all response) but failed. I can access the rest service and can see the success response in network tab, but getting the same error in console. XMLHttpRequest cannot load localhost:9082/testing/getAllProfiles. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'localhost:8082' is therefore not allowed access. @IIker Can I get any reference link to set up cors setting on spring-mvc side. Commented Mar 18, 2017 at 10:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.