add https sni example

This commit is contained in:
AJ ONeal 2019-10-27 00:55:40 -06:00
parent 0743aa5280
commit 0b91d9a26d
1 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,21 @@
'use strict';
var https = require('http2');
var tls = require('tls');
var fs = require('fs');
var key = fs.readFileSync('./privkey.pem');
var cert = fs.readFileSync('./fullchain.pem');
function SNICallback(servername, cb) {
console.log('sni:', servername);
cb(null, tls.createSecureContext({ key, cert }));
}
var server = https
.createSecureServer({ SNICallback: SNICallback }, function(req, res) {
res.end('Hello, Encrypted World!');
})
.listen(443, function() {
console.info('Listening on', server.address());
});