Skip to content

Instantly share code, notes, and snippets.

@indutny indutny/https.js
Last active Dec 18, 2015

Embed
What would you like to do?
var cluster = require('cluster');
var os = require('os');
var fs = require('fs');
var https = require('https');
if (cluster.isMaster) {
for (var i = 0; i < os.cpus().length; i++) {
cluster.fork();
}
return;
}
var options = {
key: fs.readFileSync('./test/fixtures/test_key.pem'),
cert: fs.readFileSync('./test/fixtures/test_cert.pem')
};
https.createServer(options, function(req, res) {
res.end('hello world');
}).listen(44300, function() {
console.log('listening %d', process.pid);
});
var os = require('os');
var fs = require('fs');
var crypto = require('crypto');
var cluster = require('cluster');
var http = require('http');
if (cluster.isMaster) {
for (var i = 0; i < os.cpus().length; i++) {
cluster.fork();
}
return;
}
var tls_wrap = process.binding('tls_wrap');
var DEFAULT_CIPHERS = 'ECDHE-RSA-AES128-SHA256:AES128-GCM-SHA256:' + // TLS 1.2
'RC4:HIGH:!MD5:!aNULL:!EDH'; // TLS 1.0
var credentials = crypto.createCredentials({
key: fs.readFileSync('./test/fixtures/test_key.pem'),
cert: fs.readFileSync('./test/fixtures/test_cert.pem'),
ciphers: DEFAULT_CIPHERS
});
var server = http.createServer(function(req, res) {
res.end('hello world');
}).listen(44300, function() {
console.log('listening %d', process.pid);
});
// Wrap TCPWrap handle
var handler = server.listeners('connection')[0];
server.removeAllListeners('connection');
server.on('connection', function(s) {
var wrap = tls_wrap.wrap(credentials.context, s._handle, true);
wrap.onhandshakestart = function(reused) {
};
wrap.onhandshakedone = function(reused) {
};
wrap.onerror = function(err) {
console.log(err);
};
});
server.on('connection', handler);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.