Kevin J Kevin J -3 years ago 94
Javascript Question

Why doesn't node.js server work on my subdomain (using cloudflare on WHM server)?

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?

Answer Source

Turns out it has nothing to do with cloudflare. I'm on a WHM/cpanel server and ports 2083 (SSL) and 2087 (SSL) are used by WHM.

I used port 8443 instead and it works beautifully.

So in conclusion, while cloudflare has 2083 and 2087 open, don't use these in conjunction with cpanel.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download