Securing Websockets
Websockets is a great tool for client-to-server communication via Node.js . However, as you shouldn't send data unsecured.
On the client side:
var connection = new WebSocket('wss://example.com:8080');
The "wss" is really important. That tells the client the connection is secure. On the server side:
var webSocketServer = require('websocket').server;
var https = require('https');
var options = {
key: fs.readFileSync(".your_key.pem"),
cert: fs.readFileSync("your_cert.pem"),
ca: [fs.readFileSync("your_ca.pem")]
};
var server = https.createServer(options, function(req, res){
});
And then continue as you would normally.
Written by Michael Kaminsky
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Nodejs
Authors
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#