javascript - Configure socket.io with htpps under Node.js with express and session -


i passed few days ago nodejs app under https (thanks let's encrypt )

problem socket.io won't connect anymore server. here it's front-end code (under react):

layout.jsx

sockethost: 'https://localhost:9091', ... this.socket = io(this.sockethost, {secure: true}); ... this.socket.on('update', function(data){ ... 

before https socket.io working fine (i mean code structure ok.) here it's serverside code:

index.js:

var app =  express(); app .use(session) .use((req, res, next)=>{     if(req.secure)         next();     else         res.redirect('https://' + req.headers.host + req.url); }) ... var httpserver = http.createserver(app); var httpsserver = https.createserver(credentials, app); httpserver.listen(conf.mainport); httpsserver.listen(conf.httpsport);  require('./app/socket')(httpsserver, session, store); 

app/socket.js:

... io  = require('socket.io')(conf.socketport), ios = require('socket.io-express-session'); ... module.exports = function(app, session){      var module = {};      if(app && session){         io.use(ios(session));         io.on('connection', function(socket){         .... 

i'm not using store param becaused it's useless me @ point.

and error in browser:

get https://localhost:9091/socket.io/?eio=3&transport=polling&t=1454751433013-95  net::err_connection_refused 

solution founded

while trying write resume of problem, founded solution, , problem. needed pass httpsserver socket , forget port:

app/socket.js:

 io          = require('socket.io'),  ios         = require('socket.io-express-session');  var sockets  = {};  module.exports = function(app, session){      var module = {};     if(app && session){         io = io(app);         io.use(ios(session));     ...      return module; }; 

and on front side not map port:

layout.jsx

    //useless: sockethost: 'https://localhost',      this.socket = io({secure: true}); 

so don't have question actually.. let here if stuck on same kind of trouble.

have day!


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -