From 0b91d9a26def6f994c5e25563c333e12df1a4daa Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sun, 27 Oct 2019 00:55:40 -0600 Subject: [PATCH] add https sni example --- examples/https-sni-server.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 examples/https-sni-server.js diff --git a/examples/https-sni-server.js b/examples/https-sni-server.js new file mode 100644 index 0000000..8ae52fa --- /dev/null +++ b/examples/https-sni-server.js @@ -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()); + });