I am new to node.js and got stuck on cors problem. I am sending client ajax get request from one express server to another, but at least I am not able to get response from app.all('*', function(req, res, next){console.log("request: "+req)})
GET request looks something like:
$.ajax({
type: 'GET',
url: 'http://localhost:8082/request'
});
I was also setting headers in ajax with:
'beforeSend : function(xhr) {
xhr.setRequestHeader('Access-Control-Allow-Methods', 'POST, GET, OPTIONS');
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
xhr.setRequestHeader('Access-Control-Max-Age', '1000');
xhr.setRequestHeader('Authorization', '*')},
...or setting cors module in node.js:
var cors = require('cors');
var app = express();
app.use(cors());
app.options('*',cors(),function(){
console.log("preflight")
});
In both firefox and chrome, I received no response (in chrome I got net::ERR_CONNECTION_REFUSED
)
When running node servers locally on my PC, everything works. Also curl command works fine.
Is there a chance, this is a problem with hosting/ports or am I still missing something?