0

I have a node.js application running on a Ubuntu 14.04 server, I also depend on apache because my application uses MySQL on the backend. I have apache running on port 8080 and the node app listening on port 80. (Just some preliminary information) So I got a ssl cert from letsencrpyt but It doesn't seem to be working with socket.io.

Here is my code

app.js

var favicon = require('serve-favicon');
var crypto = require("crypto");
var mysql      = require('mysql');
var http = require('http');
var fs = require('fs');
var _favicon = favicon(__dirname + '/favicon.ico');
 var connection = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    port: '3306',
    password: 'password',
   database : 'database'
 });
 connection.connect(function(err){
 if(!err) {
     console.log("mysql connected");  
 } else {
  console.log(err);
 }
 });
var https = require('https');

var options = {
key: fs.readFileSync('../privkey.pem'),
cert: fs.readFileSync('../cert.pem')
};
     var server = https.createServer(options,
      function(req, response){
        fs.readFile(__dirname + '/index.html',
          function(err, data){
       if(err){
              response.writeHead(500);
              return response.end('error');
         } else {
      _favicon(req, response, function onNext(err){
        if(err){
        response.writeHead(200);
        response.end(data);
            } else {
            response.writeHead(200);
            response.end(data);
            }
        });
         }
     })
});
var io = require('socket.io').listen(server);
server.listen(80, "0.0.0.0");

and then on the client side I do this

    <script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>
    var socket  = io.connect('https://localhost', {secure: true, port: 80});

this is probably all wrong and also how do I make it so that if people type my domain "oncampus.ws" they get redirected to the https location "https://www.oncampus.ws" ?

Matt Cieslak
  • 13
  • 1
  • 6
  • When you say "doesn't seem to be working", what do you mean, exactly? What errors do you see? What does `curl -kv https://localhost:80` show? – Castaglia Mar 21 '16 at 18:26
  • This is the error I get on the client side socket.io-1.4.5.js:1 GET https://localhost/socket.io/?EIO=3&transport=polling&t=LEQTB1T net::ERR_INSECURE_RESPONSE – Matt Cieslak Mar 21 '16 at 18:36
  • What happens if you have your Node.js app listening on port 443, rather than port 80 (and have the client code adjusted accordingly)? I'm wondering if the client code is making some assumptions about port 80... – Castaglia Mar 21 '16 at 21:09
  • Possible duplicate of [net::ERR\_INSECURE\_RESPONSE while making ajax request from node-webkit](https://stackoverflow.com/questions/26936078/neterr-insecure-response-while-making-ajax-request-from-node-webkit) – Paul Sweatte Sep 21 '17 at 22:54

0 Answers0