Search code examples
node.jshttpsnode.js-connect

HTTPS with nodejs and connect


I'm currently using nodejs with connect as my HTTP server.
Is there anyway to activate HTTPS with connect?
I cannot find any documentation about it.


Solution

  • Instead of creating http server, use https server for connect :

    var fs = require('fs');
    var connect = require('connect')
      //, http = require('http'); Use https server instead
      , https = require('https');
    
    var options = {
        key:    fs.readFileSync('ssl/server.key'),
        cert:   fs.readFileSync('ssl/server.crt'),
        ca:     fs.readFileSync('ssl/ca.crt')
    };
    var app = connect();
    https.createServer(options,app).listen(3000);
    

    See the documentation for https here and tls server (https is a subclass of tls) here