Tuesday, February 28, 2017

NodeJS not working on https (port 3000)

I'm working with both laravel and nodejs (linking socket.io with redis from backend to frontend). My code on node.js file is:

var app = require('express')();
var server = require('https').Server(app);
var io = require('socket.io')(server);
const redis = require('redis');
const redisClient = redis.createClient();


server.listen(3000);

io.on('connection', function(socket){
    console.log('a user connected');
    });

redisClient.subscribe('business');
console.log("Redis server running");
redisClient.on("message", function(channel, message) {
    console.log(channel);
    console.log(message);
            io.emit(channel, message);
});

also, here is the socket.io connection.

var socket = io('https://domain.com:3000');

I keep getting:

GET http://ift.tt/2mHGXKJ;     t=1488315350710-12 net::ERR_CONNECTION_TIMED_OUT

I had this problem before on my localhost, but I solved it by setting the socket = io('domain:3000') instead of io(); because on 8080/8443 I have laravel, while on 3000 I have node.js running. I'm getting this error while having nodejs running on server (ubuntu). Thanks




via terror

Advertisement