2

I am using parse.com cloud code and has a function inside, which is called using a https post call from my angularjs.

When I test the same function from POSTMAN REST client it works.

But from my domain it gives a CORS error

XMLHttpRequest cannot load https://api.parse.com/1/functions/sendemail. Response to preflight request doesn't pass access control check: A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. Origin 'http://www.crickify.com' is therefore not allowed access.

Cloud Code:

Parse.Cloud.define("sendemail", function(request, response) {
  //response.success("Hello world!");
  var mailgun = require('mailgun');
  console.log("from parselog",request.params);

  response.set("Access-Control-Allow-Origin", "http://www.crickify.com");
     response.set("Access-Control-Allow-Headers", "X-Requested-With");
     response.set('Access-Control-Allow-Headers', 'Content-Type');

  mailgun.initialize('XXX', 'XXX');
  mailgun.sendEmail({
    to: "bala@mindlens.com.sg",
    from: "Mailgun@CloudCode.com",
    subject: "Hello from Cloud Code!",
    text: "Using Parse and Mailgun is great!"
}, {
    success: function(httpResponse) {
        console.log(httpResponse);
        response.success("Email sent!");
    },
    error: function(httpResponse) {
       console.error(httpResponse);
       response.error(httpResponse);
    }
});
});

Angular Code:

$scope.sendemail = function(passedEmail) {
             // body...
             var email = passedEmail;
             var message = {mail:email};
             $http({
                    method: 'POST',
                    url: 'https://[app key]:jskey]@api.parse.com/1/functions/sendemail',
                    data: message
                })
                .success(function(data) {
                    console.log("Success" + data);
                })
                .error(function(error) {
                    console.log("Success" + data);
                });
           }
Bala Sivagnanam
  • 863
  • 1
  • 15
  • 30

0 Answers0