Skip to content

Instantly share code, notes, and snippets.

@giavac
Created February 6, 2015 17:49
Show Gist options
  • Save giavac/1200275c7ff0103cc095 to your computer and use it in GitHub Desktop.
Save giavac/1200275c7ff0103cc095 to your computer and use it in GitHub Desktop.
Decorate the WebSocket module with an HTTPS server
var ws_cfg = {
ssl: true,
port: 8080,
ssl_key: '/path/to/ssl.key',
ssl_cert: '/path/to/ssl.crt'
};
var processRequest = function(req, res) {
console.log("Request received.")
};
var httpServ = require('https');
var app = null;
app = httpServ.createServer({
key: fs.readFileSync(ws_cfg.ssl_key),
cert: fs.readFileSync(ws_cfg.ssl_cert)
}, processRequest).listen(ws_cfg.port);
//var WebSocketServer = require('ws').Server, ws_server = new WebSocketServer(ws_cfg);
var WebSocketServer = require('ws').Server, ws_server = new WebSocketServer( {server: app});
@joeytwiddle
Copy link

joeytwiddle commented Aug 30, 2016

This is a condensed version of the example in the websockets/ws repo.

It was discussed in the blog post: WebSockets over Node.js: from Plain to Secure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment