Here is a simple note on how to serving content via node.js with HTTPS and make browser accept the certificate automatically.
First, use this commend from this The Most Common OpenSSL Commands to create your private key and certificate:
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout privateKey.key -out certificate.crt
Second, install the certificate.crt to Keychain in Mac (You may need other solution for other OS). Follow the instructions in this Google Chrome, Mac OS X and Self-Signed SSL Certificates.
Last, I'm using the Connect middleware lib for node.js. To serve via HTTPS, you need something like:
var connect = require('connect'),
http = require('http'),
https = require('https'),
fs = require('fs');
var app = connect().
// ...
// configure app accordingly
key: fs.readFileSync('privateKey.key'),
cert: fs.readFileSync('certificate.crt')
};
https.createServer(options, app).listen(9999);
That's it. Once you start your server via node, you should be able to access your content via HTTPS.
Useful & Great Article for NodeJS Development
ReplyDeleteNode.js Training Node.js Online Training | Node.js Training in Chennai