My node.js server works beautifully on my live website "https://www.example.com", however the development environment throws the following console error:
"XMLHttpRequest cannot load https://dev.example.com:2083/socket.io/?EIO=3&transport=polling&t=LtTLz1_. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://dev.example.com' is therefore not allowed access. The response had HTTP status code 522."
I'm using cloudflare and I have two node.js servers running, the live server runs on port 2053 and the dev runs on port 2083.
I tried several methods to add the header Access-Control-Allow-Origin:* and nothing seems to work.
Here is the top portion of my node.js script:
var fs = require('fs');
var options = {
ca: fs.readFileSync(__dirname + '/ca.pem'),
key: fs.readFileSync(__dirname + '/file.pem'),
cert: fs.readFileSync(__dirname + '/file.crt')
};
var express = require('express'),
app = express();
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");
next();
});
var https = require('https'),
server = https.createServer(options, app),
io = require('socket.io').listen(server);
server.listen(2083);
Is there something I'm missing here?