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 "", however the development environment throws the following console error:

"XMLHttpRequest cannot load No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '' 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");

var https = require('https'),
server = https.createServer(options, app),
io = require('').listen(server);


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