Created
February 6, 2015 17:49
-
-
Save giavac/1200275c7ff0103cc095 to your computer and use it in GitHub Desktop.
Decorate the WebSocket module with an HTTPS server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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