I have disabled my firewall (ufw on Ubuntu 15.04 server). This seems to be the most common cause of this problem.
Additionally some people have problems using AJAX, so I tried with both ajax and an https POST request. My code is as follows:
jQuery making the request:
testData = {
email : address,
subject : subject,
body : body,
meetingId : meetingId
};
testData = JSON.stringify(testData);
$.ajax({
url: "https://localhost:3000/sendICSInvite",
contentType: "application/json; charset=utf-8",
data: testData,
type: "POST",
success: function(result) {
console.log("request might have worked");
console.log(result);
},
error: function (err) {
console.log(err);
}
});
To the route:
var api = require("../controllers/main.js");
//API ROUTES
module.exports = function(app){
app.post('/sendICSInvite', api.sendEmail);
};
The controller:
module.exports.sendEmail = function (req, res) {
console.log("sending Email (probably not actually)");
});
This can be called with postman and works flawlessly. When I do a call from jQuery, however, it fails and returns the error:
OPTIONS https://localhost:3000/sendICSInvite?email=myemail%40myprovider.com&subject=TE…+emails&body=Just+testing+the+function+for+autmoated+email&meetingId=33033 net::ERR_CONNECTION_REFUSEDsend
@ jquery.js:4m.extend.ajax
@ jquery.js:4sendEmail
@ caseman.js:706(anonymous function)
@ VM4606:2InjectedScript._evaluateOn
@ VM4491:875InjectedScript._evaluateAndWrap
@ VM4491:808InjectedScript.evaluate
@ VM4491:664
Seems to be related to the OPTIONS request (I don't know where this is sent, I sepcifiy POST type in my ajax), which lead me to this proposed solution in my node server:
app.use(function(req, res, next) {
res.header('Access-Control-Allow-Origin', "*");
res.header('Access-Control-Allow-Methods',"GET,PUT,POST,DELETE,OPTIONS");
res.header('Access-Control-Allow-Headers', "*");
next();
});
But even with this middleware function the error stays the same. The node server is running on port 3000 on a virtual box using VMware Workstation and running Ubuntu 15.04 server edition. The website containing the jQuery that I want to issue this request is served through a Perl script on port 80.