Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

https sni example

  • Loading branch information...
commit 7fbc21b6c133c4a742f998f5b59366b3eb07d293 1 parent 96763eb
@substack authored
Showing with 39 additions and 0 deletions.
  1. +34 −0 example/http-https-sni.js
  2. +5 −0 readme.markdown
View
34 example/http-https-sni.js
@@ -0,0 +1,34 @@
+var fs = require('fs');
+var crypto = require('crypto');
+var bouncy = require('bouncy');
+
+bouncy(function (req, bounce) {
+ if (req.headers.host === 'beep.example.com') {
+ bounce(8001);
+ }
+ else if (req.headers.host === 'boop.example.com') {
+ bounce(8002);
+ }
+}).listen(8000);
+
+// Listen to an SSL port at the same time.
+// Use SNI to serve different certificates
+// based on the hostname (vhost).
+
+var ssl = {
+ key : fs.readFileSync('/etc/ssl/private/default.key'),
+ cert : fs.readFileSync('/etc/ssl/private/default.crt'),
+ SNICallback: sni_select
+};
+
+bouncy(ssl, function (req, bounce) {
+ bounce(8000)
+}).listen(8043)
+
+function sni_select(hostname) {
+ var creds = {
+ key: fs.readFileSync('/etc/ssl/private/'+hostname+'/private.key'),
+ cert: fs.readFileSync('/etc/ssl/private/'+hostname+'/server.crt')
+ };
+ return crypto.createCredentials(creds).context
+}
View
5 readme.markdown
@@ -43,6 +43,11 @@ If the arity of `cb` is 3, you'll get the response object `res` in
`cb(req, res, bounce)`.
Otherwise you just get `cb(req, bounce)`.
+If you are using more than one SSL cert, add `opts.SNICallback`.
+See the example http-https-sni.js and the
+[nodejs tls page](http://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener)
+for details.
+
## bounce(stream, opts={})
Call this function when you're ready to bounce the request to a stream.
Please sign in to comment.
Something went wrong with that request. Please try again.