Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial https mode with readme notes

  • Loading branch information...
commit a2e3243b1d8842b1ec690670460f13719a9549f0 1 parent 4e6d8f6
@substack authored
Showing with 31 additions and 5 deletions.
  1. +6 −3 README.markdown
  2. +12 −0 example/https.js
  3. +13 −2 index.js
View
9 README.markdown
@@ -7,7 +7,7 @@ they need to go in an entirely transparent way.
Use bouncy as a load balancer or http host router, either programmatically or
with the simple command-line tool.
-Bouncy is websocket-capable.
+Bouncy is websocket and tls (https) capable.
Bouncy 0.0.4 is [faster than http-proxy 0.7.3](https://gist.github.com/1275259) in
[this benchmark](https://github.com/substack/bouncy/tree/master/bench).
@@ -55,11 +55,14 @@ Use a colon-separated string to specify a host and port in a route.
Use `""` for the host as a default route.
-bouncy(cb)
-==========
+bouncy(opts={}, cb)
+===================
`bouncy(cb)` returns a new net.Server object that you can `.listen()` on.
+If you specify `opts.key` and `opts.cert`, the connection will be set to secure
+mode using tls. Do this if you want to make an https router.
+
Your callback `cb` will get these arguments:
req
View
12 example/https.js
@@ -0,0 +1,12 @@
+var fs = require('fs');
+var opts = {
+ key : fs.readFileSync(__dirname + '/https/privatekey.pem'),
+ cert : fs.readFileSync(__dirname + '/https/certificate.pem')
+};
+
+var bouncy = require('bouncy');
+bouncy(opts, function (req, bounce) {
+ bounce(8000);
+}).listen(7000);
+
+console.log('https://localhost:7000');
View
15 index.js
@@ -6,9 +6,20 @@ var insertHeaders = require('./lib/insert_headers');
var parseArgs = require('./lib/parse_args');
var net = require('net');
+var tls = require('tls');
-var bouncy = module.exports = function (cb) {
- return net.createServer(handler.bind(null, cb));
+var bouncy = module.exports = function (opts, cb) {
+ if (typeof opts === 'function') {
+ cb = opts;
+ opts = {};
+ }
+
+ if (opts && opts.key && opts.cert) {
+ return tls.createServer(opts, handler.bind(null, cb));
+ }
+ else {
+ return net.createServer(handler.bind(null, cb));
+ }
};
var handler = bouncy.handler = function (cb, c) {
Please sign in to comment.
Something went wrong with that request. Please try again.