From 07091b5077a40dfee29f6fd33ecb38d3fa25b801 Mon Sep 17 00:00:00 2001 From: srossross Date: Mon, 16 Sep 2013 11:21:20 -0700 Subject: [PATCH] ENH: updated README and added examples file. --- README.md | 29 +++++++++++++++++++++++++++++ examples/stand-alone.js | 15 +++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 examples/stand-alone.js diff --git a/README.md b/README.md index ea381d2..dcede45 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,24 @@ You can easily add a `pass` (stages) into both the pipelines (XXX: ADD API). In addition, every stage emits a corresponding event so introspection during the process is always available. +#### Setup a basic stand-alone proxy server + +var http = require('http'), + caronte = require('caronte'); +// +// Create your proxy server +// +caronte.createProxyServer({target:'http://localhost:9000'}).listen(8000); + +// +// Create your target server +// +http.createServer(function (req, res) { + res.writeHead(200, { 'Content-Type': 'text/plain' }); + res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2)); + res.end(); +}).listen(9000); + #### Setup a stand-alone proxy server with custom server logic ``` js @@ -72,6 +90,17 @@ server.listen(5050); * Commit to your local branch (which must be different from `master`) * Submit your Pull Request (be sure to include tests and update documentation) +### Options + +`caronte.createProxyServer` supports the following options: + + * **target**: + * **forward**: + * **ssl**: object to be passed to https.createServer() + * **ws**: true/false, if you want to proxy websockets + * **xfwd**: true/false, adds x-forward headers + * **maxSock**: maximum number of sockets + ### Test ``` diff --git a/examples/stand-alone.js b/examples/stand-alone.js new file mode 100644 index 0000000..d3848ab --- /dev/null +++ b/examples/stand-alone.js @@ -0,0 +1,15 @@ +var http = require('http'), + caronte = require('caronte'); +// +// Create your proxy server +// +caronte.createProxyServer({target:'http://localhost:9000'}).listen(8000); + +// +// Create your target server +// +http.createServer(function (req, res) { + res.writeHead(200, { 'Content-Type': 'text/plain' }); + res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2)); + res.end(); +}).listen(9000); \ No newline at end of file