Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Sep 2011
    Posts
    428
    Thanks
    18
    Thanked 26 Times in 26 Posts

    Using Node.js and socket.io with SSL encryption for SSL site

    So basically, I have a social site I'm building/running on a paid webhost (I know that self hosted is better but I got this at a great deal and it saves me time to manage sites and avoid the risk of crashing all my sites from misconfiguration). The site's domain is running on an SSL encryption (HTTPS), so I can only include pages with HTTPS support. This was all fine until I wanted to setup a chat server in it. I have this running on a separate VPS system, small enough just to run the node server but large enough to not lag from it. What I need to do is convert the current script I have to support SSL encryption and accept an SSL encryption, so that the page doesn't throw an error for unsafe content being loaded.

    In a short version, I need to convert the (partial) script below to listen/serve on HTTPS/WSS. I purchased an SSL certificate (for around $12) but have no Idea on whether or not it's actually needed, or how to configure it to work.

    Here is my (partial) script:

    (I wrap it in PHP tags to get some basic syntax highlighting)
    PHP Code:
    var port_listen 80;     //Port to listen on

    var request = require("request");
    var 
    jar request.jar(); //Used in user authentication checking (sending cookies) with the main server
    var url = require('url');

    var 
    https = require('https');

    var 
    app = require('express')();
    var 
    http = require('http').Server(app);
    var 
    io = require('socket.io')(http);

    app.get('/', function(reqres){
        
    res.sendfile('index.html');
    });

    io.sockets.on('connection', function(socket){
        
    /* Do stuff here */
        /*  --cut out--  */
    });

    http.listen(port_listen, function(){
        
    console.log('listening on *:' port_listen);
    }); 

    I'm not sure what is needed, what needs changed, what should be removed, etc.
    I was testing partially on this file and then moved to an alternate one to test with so I could keep the working non-secure version in tact. I hope this can be resolved soon so that I can re-enable the forced HTTPS on my site.

  • #2
    Regular Coder
    Join Date
    Sep 2011
    Posts
    428
    Thanks
    18
    Thanked 26 Times in 26 Posts
    Never mind, I finally found a post online that helped me fix this issue. If anyone else needs it, here you go!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •