0

I'm successfully listenin port 443 and can access server over https, but I can't access it with http.

var fs = require('fs')
options = {
    ca : fs.readFileSync('./ssl/site.com.pem'),
    key: fs.readFileSync('./ssl/site.com.key'),
    cert: fs.readFileSync('./ssl/site_com.crt')
}

var app = require('express.io')
app.https(options).io()
....
app.listen(443);

I've tried using http and https modules:

app.http().io();
http.createServer(app).listen(80);
https.createServer(options, app).listen(443);

But this time socket.io is giving 404 in browser. How can I solve this? I need to use Express.Io's socket connection because application is based on it.

Lazy
  • 1,807
  • 4
  • 29
  • 49

2 Answers2

0

You should redirect http to https

 var express = require('express'),
 app = express(),  
 httpapp = express();

  //........................

 var credentials = {key: privateKey, cert: certificate, ca: ca};
 var httpsServer = https.createServer(credentials, app);
 var httpServer = http.createServer(httpapp);


 httpsServer.listen(443);
 httpServer.listen(80); 


 httpapp.route('*').get(function(req,res){  
    res.redirect('https://yourdomain.com'+req.url)
 });
Paramore
  • 1,313
  • 2
  • 19
  • 37
0

Had the same problem a few days ago, and this GitHub issue helped: https://github.com/techpines/express.io/issues/17#issuecomment-26191447

Your code is on the right way, it just need some changes. The code below is a slightly modified version of the snippet you provided.

var fs = require('fs'),
    express = require('express.io');

options = {
    ca : fs.readFileSync('./ssl/site.com.pem'),
    key: fs.readFileSync('./ssl/site.com.key'),
    cert: fs.readFileSync('./ssl/site_com.crt')
};

var app = express();
app.https(options).io();
var httpServer = require('http').createServer(app);

// ...

app.listen(443);
express.io.listen(httpServer);
httpServer.listen(80, function() { }, function() { });
Victor Gama
  • 35
  • 1
  • 5