I have Angular 2 typescript application running on my localhost. I have to access external REST API in my application. Whenever I try to access, I get this error
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at ***. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
What is the best solution to fix this issue. I dont want to use any plugin/addOns. I dont think so this package would work for Angular 2 Typescript application.It is used for express.js
npm install cors --save
How do I set this CORS header ‘Access-Control-Allow-Origin’ using typescript for entire project/application? Where do I need to add this header in below code?
var request = new XMLHttpRequest();
let myurl='http://remoteIP/api';
request.open('GET', myurl, true);
request.responseType = 'blob';
request.onload = function() {
var reader = new FileReader();
reader.readAsDataURL(request.response);
reader.onload = (e) => {
console.log('DataURL:', reader.result);
};
};
request.send();
Access-Control-Allow-Originheader to the responses that need it (i.e., the ones access through Ajax calls).http://ci.jruby.org/job/jruby-base/lastSuccessfulBuild/in my angular typescript application. Angular application is on my localhost. This is when I get the CORS issue.