F
F
fr0zen2017-06-09 08:35:22
Angular
fr0zen, 2017-06-09 08:35:22

How to solve angularjs CORS issue?

There is an Anlugar code:

.controller('OpinionFeed', ['$scope','$http', function OpinionFeed($scope,$http) {
          $http({
              method: 'GET',
              url: 'localhost:3000/insta',
              //dataType: 'jsonp'
          }).then(function successCallback(response) {
              console.log(response);
          }, function errorCallback(response) {
              // called asynchronously if an error occurs
              // or server returns response with an error status.
          });
      }]);

There is a code on the backend:
app.use(function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With,     Content-Type, Accept");
    res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
    next();
});
app.get('/insta', function (req, res) {
    ig.tag_media_recent('7daystoworld', function(err, medias, pagination, remaining, limit) {
        res.send(medias);
        console.log(medias);
});

Angular to localhost:8000, backend to localhost:3000. When I try to call the backend method, an error appears in the console: cc60a8f9c52c47e88f6c3f9621d499da.PNG
Question: what am I doing wrong and how to fix it. Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2017-06-09
@fr0zen

http://localhost:3000/insta

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question