Heroku - Socket.IO Client Always Connects To Localhost Heroku - Socket.IO Client Always Connects To Localhost heroku heroku

Heroku - Socket.IO Client Always Connects To Localhost


This works for me if I use for client:

const socketURL =  process.env.NODE_ENV === 'production'    ? window.location.hostname    : 'https://localhost:5000';const socket = io.connect(socketURL, {secure: true});


Your website runs on https, but socket on http. Use a secure URL for your initial connection, i.e. instead of "http://" use "https://"

var socket = io.connect('https://test.herokuapp.com', {secure: true});

Or open your website at http://test.herokuapp.com (without ssl)