From bdeabb767a537bcb9f98ef74f6efe9762a9b1c34 Mon Sep 17 00:00:00 2001 From: cronopio Date: Mon, 18 Nov 2013 15:21:25 -0500 Subject: [PATCH 01/16] [examples] deleted this examples --- examples/concurrent-proxy.js | 36 ------------------------------------ examples/error-handling.js | 33 --------------------------------- examples/forward-proxy.js | 33 --------------------------------- examples/https-secure.js | 16 ---------------- examples/https.js | 13 ------------- examples/stand-alone.js | 17 ----------------- 6 files changed, 148 deletions(-) delete mode 100644 examples/concurrent-proxy.js delete mode 100644 examples/error-handling.js delete mode 100644 examples/forward-proxy.js delete mode 100644 examples/https-secure.js delete mode 100644 examples/https.js delete mode 100644 examples/stand-alone.js diff --git a/examples/concurrent-proxy.js b/examples/concurrent-proxy.js deleted file mode 100644 index 0d1889f89..000000000 --- a/examples/concurrent-proxy.js +++ /dev/null @@ -1,36 +0,0 @@ -var http = require('http'), - httpProxy = require('../lib/http-proxy'); - -var connections = [], - go; - - -// -// Target Http Server -// -// to check apparent problems with concurrent connections -// make a server which only responds when there is a given nubmer on connections -// -http.createServer(function (req, res) { - connections.push(function () { - res.writeHead(200, { 'Content-Type': 'text/plain' }); - res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2)); - res.end(); - }); - - process.stdout.write(connections.length + ', '); - - if (connections.length > 10 || go) { - go = true; - while (connections.length) { - connections.shift()(); - } - } -}).listen(9000); -console.log("Web server listening on port 9000"); - -// -// Basic Http Proxy Server -// -httpProxy.createProxyServer({target:'http://localhost:9000'}).listen(8000); -console.log("Proxy server listening on port 8000"); \ No newline at end of file diff --git a/examples/error-handling.js b/examples/error-handling.js deleted file mode 100644 index 76a09d955..000000000 --- a/examples/error-handling.js +++ /dev/null @@ -1,33 +0,0 @@ -var httpProxy = require('../lib/http-proxy'), - http = require('http'); -/* - * Create your proxy server - */ -var proxy = httpProxy.createProxyServer({target:'http://localhost:30404', ws:true}); - -var proxyServer = http.createServer(requestHandler); - -function requestHandler(req, res) { - // Pass a callback to the web proxy method - // and catch the error there. - proxy.web(req, res, function (err) { - // Now you can get the err - // and handle it by your self - // if (err) throw err; - res.writeHead(502); - res.end("There was an error proxying your request"); - }); - - // In a websocket request case - req.on('upgrade', function (req, socket, head) { - proxy.ws(req, socket, head, function (err) { - // Now you can get the err - // and handle it by your self - // if (err) throw err; - socket.close(); - }) - }) -} - -console.log("Proxy server is listening on port 8000"); -proxyServer.listen(8000) \ No newline at end of file diff --git a/examples/forward-proxy.js b/examples/forward-proxy.js deleted file mode 100644 index 4cb516f50..000000000 --- a/examples/forward-proxy.js +++ /dev/null @@ -1,33 +0,0 @@ -var http = require('http'), - httpProxy = require('../lib/http-proxy'); - -// -// Target Http Server -// -http.createServer(function (req, res) { - res.writeHead(200, { 'Content-Type': 'text/plain' }); - res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2)); - res.end(); -}).listen(9000); -console.log("Web server listening on port 9000"); - -// -// Target Http Forwarding Server -// -http.createServer(function (req, res) { - console.log('Receiving forward for: ' + req.url); - res.writeHead(200, { 'Content-Type': 'text/plain' }); - res.write('request successfully forwarded to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2)); - res.end(); -}).listen(9001); - -// -// Basic Http Proxy Server -// Forward example: send requests without care about response -// -httpProxy.createServer({ - target: 'http://localhost:9000', - forward: 'http://localhost:9001' -}).listen(8000) -console.log("Proxy server listening on port 8000"); - diff --git a/examples/https-secure.js b/examples/https-secure.js deleted file mode 100644 index 83b87eb7c..000000000 --- a/examples/https-secure.js +++ /dev/null @@ -1,16 +0,0 @@ -var httpProxy = require('../lib/http-proxy'), - https = require('https'); -/* - * Create your proxy server pointing to a secure domain - * Enable ssl validation - */ -var options = { - target : 'https://google.com', - agent : https.globalAgent, - headers: {host: 'google.com'} -}; - -var proxyServer = httpProxy.createProxyServer(options); -console.log("Proxy server listening on port 8000"); -proxyServer.listen(8000); - diff --git a/examples/https.js b/examples/https.js deleted file mode 100644 index 364d7cb2f..000000000 --- a/examples/https.js +++ /dev/null @@ -1,13 +0,0 @@ -var httpProxy = require('../lib/http-proxy'); -/* - * Create your proxy server pointing to a secure domain - */ -var options = { - target:'https://google.com', - headers: {host: 'google.com'} -}; - -var proxyServer = httpProxy.createProxyServer(options); -console.log("Proxy server listening on port 8000"); -proxyServer.listen(8000); - diff --git a/examples/stand-alone.js b/examples/stand-alone.js deleted file mode 100644 index e5239c460..000000000 --- a/examples/stand-alone.js +++ /dev/null @@ -1,17 +0,0 @@ -var http = require('http'), - httpProxy = require('../lib/http-proxy'); -// -// Create your proxy server -// -console.log("Proxy server listening on port 8000"); -httpProxy.createProxyServer({target:'http://localhost:9000'}).listen(8000); - -// -// Create your target server -// -console.log("Web server listening on port 9000"); -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 From 7e44d3669bbd1b13e6452f265d52b22396f68b5d Mon Sep 17 00:00:00 2001 From: cronopio Date: Mon, 18 Nov 2013 15:37:34 -0500 Subject: [PATCH 02/16] [examples] update old examples --- examples/http/basic-proxy.js | 60 +++++++++++++++++++++++++++ examples/http/concurrent-proxy.js | 68 +++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 examples/http/basic-proxy.js create mode 100644 examples/http/concurrent-proxy.js diff --git a/examples/http/basic-proxy.js b/examples/http/basic-proxy.js new file mode 100644 index 000000000..8d781604d --- /dev/null +++ b/examples/http/basic-proxy.js @@ -0,0 +1,60 @@ +/* + basic-proxy.js: Basic example of proxying over HTTP + + Copyright (c) 2010 Charlie Robbins, Mikeal Rogers, Fedor Indutny, & Marak Squires. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +*/ + +var util = require('util'), + colors = require('colors'), + http = require('http'), + httpProxy = require('../../lib/http-proxy'); + +var welcome = [ + '# # ##### ##### ##### ##### ##### #### # # # #', + '# # # # # # # # # # # # # # # # ', + '###### # # # # ##### # # # # # # ## # ', + '# # # # ##### ##### ##### # # ## # ', + '# # # # # # # # # # # # # ', + '# # # # # # # # #### # # # ' +].join('\n'); + +util.puts(welcome.rainbow.bold); + +// +// Basic Http Proxy Server +// +httpProxy.createServer({ + target:'http://localhost:9000' +}).listen(8000); + +// +// Target Http Server +// +http.createServer(function (req, res) { + res.writeHead(200, { 'Content-Type': 'text/plain' }); + res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2)); + res.end(); +}).listen(9000); + +util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow); +util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow); diff --git a/examples/http/concurrent-proxy.js b/examples/http/concurrent-proxy.js new file mode 100644 index 000000000..fd05442e3 --- /dev/null +++ b/examples/http/concurrent-proxy.js @@ -0,0 +1,68 @@ +/* + concurrent-proxy.js: check levelof concurrency through proxy. + + Copyright (c) 2010 Charlie Robbins, Mikeal Rogers, Fedor Indutny, & Marak Squires. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +*/ + +var util = require('util'), + colors = require('colors'), + http = require('http'), + httpProxy = require('../../lib/http-proxy'); + +// +// Basic Http Proxy Server +// +httpProxy.createServer({ + target:'http://localhost:9000' +}).listen(8000); + +// +// Target Http Server +// +// to check apparent problems with concurrent connections +// make a server which only responds when there is a given nubmer on connections +// + + +var connections = [], + go; + +http.createServer(function (req, res) { + connections.push(function () { + res.writeHead(200, { 'Content-Type': 'text/plain' }); + res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2)); + res.end(); + }); + + process.stdout.write(connections.length + ', '); + + if (connections.length > 110 || go) { + go = true; + while (connections.length) { + connections.shift()(); + } + } +}).listen(9000); + +util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow); +util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow); From b7261161343c3471201d6de36ba1030aced26425 Mon Sep 17 00:00:00 2001 From: cronopio Date: Mon, 18 Nov 2013 15:58:44 -0500 Subject: [PATCH 03/16] [examples] update forward and custom error examples --- examples/http/custom-proxy-error.js | 55 +++++++++++++++++++ examples/http/forward-and-target-proxy.js | 67 +++++++++++++++++++++++ examples/http/forward-proxy.js | 53 ++++++++++++++++++ 3 files changed, 175 insertions(+) create mode 100644 examples/http/custom-proxy-error.js create mode 100644 examples/http/forward-and-target-proxy.js create mode 100644 examples/http/forward-proxy.js diff --git a/examples/http/custom-proxy-error.js b/examples/http/custom-proxy-error.js new file mode 100644 index 000000000..5835e881c --- /dev/null +++ b/examples/http/custom-proxy-error.js @@ -0,0 +1,55 @@ +/* + custom-proxy-error.js: Example of using the custom `proxyError` event. + + Copyright (c) 2010 Charlie Robbins, Mikeal Rogers, Fedor Indutny, & Marak Squires. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +*/ + +var util = require('util'), + colors = require('colors'), + http = require('http'), + httpProxy = require('../../lib/http-proxy'); + +// +// Http Proxy Server with bad target +// +var proxy = httpProxy.createServer({ + target:'http://localhost:9000' +}); + +// +// Tell the proxy to listen on port 8000 +// +proxy.listen(8000); + +// +// Listen for the `error` event on `proxy`. +proxy.on('error', function (err, req, res) { + res.writeHead(500, { + 'Content-Type': 'text/plain' + }); + + res.end('Something went wrong. And we are reporting a custom error message.'); +}); + + +util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8000 '.yellow + 'with custom error message'.magenta.underline); \ No newline at end of file diff --git a/examples/http/forward-and-target-proxy.js b/examples/http/forward-and-target-proxy.js new file mode 100644 index 000000000..9ecf4dcec --- /dev/null +++ b/examples/http/forward-and-target-proxy.js @@ -0,0 +1,67 @@ +/* + forward-and-target-proxy.js: Example of proxying over HTTP with additional forward proxy + + Copyright (c) 2010 Charlie Robbins, Mikeal Rogers, Fedor Indutny, & Marak Squires. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +*/ + +var util = require('util'), + colors = require('colors'), + http = require('http'), + httpProxy = require('../../lib/http-proxy'); + +// +// Setup proxy server with forwarding +// +httpProxy.createServer({ + target: { + port: 9000, + host: 'localhost' + }, + forward: { + port: 9001, + host: 'localhost' + } +}).listen(8000); + +// +// Target Http Server +// +http.createServer(function (req, res) { + res.writeHead(200, { 'Content-Type': 'text/plain' }); + res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2)); + res.end(); +}).listen(9000); + +// +// Target Http Forwarding Server +// +http.createServer(function (req, res) { + util.puts('Receiving forward for: ' + req.url); + res.writeHead(200, { 'Content-Type': 'text/plain' }); + res.write('request successfully forwarded to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2)); + res.end(); +}).listen(9001); + +util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8000 '.yellow + 'with forward proxy'.magenta.underline); +util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow); +util.puts('http forward server '.blue + 'started '.green.bold + 'on port '.blue + '9001 '.yellow); \ No newline at end of file diff --git a/examples/http/forward-proxy.js b/examples/http/forward-proxy.js new file mode 100644 index 000000000..d10a40208 --- /dev/null +++ b/examples/http/forward-proxy.js @@ -0,0 +1,53 @@ +/* + forward-proxy.js: Example of proxying over HTTP with additional forward proxy + + Copyright (c) 2010 Charlie Robbins, Mikeal Rogers, Fedor Indutny, & Marak Squires. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +*/ + +var util = require('util'), + colors = require('colors'), + http = require('http'), + httpProxy = require('../../lib/http-proxy'); + +// +// Setup proxy server with forwarding +// +httpProxy.createServer({ + forward: { + port: 9000, + host: 'localhost' + } +}).listen(8000); + +// +// Target Http Forwarding Server +// +http.createServer(function (req, res) { + util.puts('Receiving forward for: ' + req.url); + res.writeHead(200, { 'Content-Type': 'text/plain' }); + res.write('request successfully forwarded to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2)); + res.end(); +}).listen(9000); + +util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8000 '.yellow + 'with forward proxy'.magenta.underline); +util.puts('http forward server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow); \ No newline at end of file From e02317ce86ff2dabd496cf7e2741e219a22ac817 Mon Sep 17 00:00:00 2001 From: cronopio Date: Tue, 19 Nov 2013 11:06:06 -0500 Subject: [PATCH 04/16] [examples] updated old proxy examples --- examples/http/proxy-https-to-http.js | 60 +++++++++++++++++++++++++++ examples/http/proxy-https-to-https.js | 59 ++++++++++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 examples/http/proxy-https-to-http.js create mode 100644 examples/http/proxy-https-to-https.js diff --git a/examples/http/proxy-https-to-http.js b/examples/http/proxy-https-to-http.js new file mode 100644 index 000000000..7c9d1fd93 --- /dev/null +++ b/examples/http/proxy-https-to-http.js @@ -0,0 +1,60 @@ +/* + proxy-https-to-http.js: Basic example of proxying over HTTPS to a target HTTP server + + Copyright (c) 2010 Charlie Robbins, Mikeal Rogers, Fedor Indutny, & Marak Squires. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +*/ + +var https = require('https'), + http = require('http'), + util = require('util'), + path = require('path'), + fs = require('fs'), + colors = require('colors'), + httpProxy = require('../../lib/http-proxy'), + fixturesDir = path.join(__dirname, '..', '..', 'test', 'fixtures'); + +// +// Create the target HTTP server +// +http.createServer(function (req, res) { + res.writeHead(200, { 'Content-Type': 'text/plain' }); + res.write('hello http over https\n'); + res.end(); +}).listen(9000); + +// +// Create the HTTPS proxy server listening on port 8000 +// +httpProxy.createServer({ + target: { + host: 'localhost', + port: 9000 + }, + ssl: { + key: fs.readFileSync(path.join(fixturesDir, 'agent2-key.pem'), 'utf8'), + cert: fs.readFileSync(path.join(fixturesDir, 'agent2-cert.pem'), 'utf8') + } +}).listen(8000); + +util.puts('https proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow); +util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow); diff --git a/examples/http/proxy-https-to-https.js b/examples/http/proxy-https-to-https.js new file mode 100644 index 000000000..2ff9151e2 --- /dev/null +++ b/examples/http/proxy-https-to-https.js @@ -0,0 +1,59 @@ +/* + proxy-https-to-https.js: Basic example of proxying over HTTPS to a target HTTPS server + + Copyright (c) 2010 Charlie Robbins, Mikeal Rogers, Fedor Indutny, & Marak Squires. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +*/ + +var https = require('https'), + http = require('http'), + util = require('util'), + fs = require('fs'), + path = require('path'), + colors = require('colors'), + httpProxy = require('../../lib/http-proxy'), + fixturesDir = path.join(__dirname, '..', '..', 'test', 'fixtures'), + httpsOpts = { + key: fs.readFileSync(path.join(fixturesDir, 'agent2-key.pem'), 'utf8'), + cert: fs.readFileSync(path.join(fixturesDir, 'agent2-cert.pem'), 'utf8') + }; + +// +// Create the target HTTPS server +// +https.createServer(httpsOpts, function (req, res) { + res.writeHead(200, { 'Content-Type': 'text/plain' }); + res.write('hello https\n'); + res.end(); +}).listen(9000); + +// +// Create the proxy server listening on port 443 +// +httpProxy.createServer({ + ssl: httpsOpts, + target: 'https://localhost:9000', + secure: false +}).listen(8000); + +util.puts('https proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow); +util.puts('https server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow); From 588327c2c4392618b515164989f08ef20a30842b Mon Sep 17 00:00:00 2001 From: cronopio Date: Tue, 19 Nov 2013 11:29:06 -0500 Subject: [PATCH 05/16] [examples] updated old examples --- examples/http/latent-proxy.js | 54 +++++++++++++++++++++++++++++++ examples/http/standalone-proxy.js | 54 +++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 examples/http/latent-proxy.js create mode 100644 examples/http/standalone-proxy.js diff --git a/examples/http/latent-proxy.js b/examples/http/latent-proxy.js new file mode 100644 index 000000000..e2aef9b72 --- /dev/null +++ b/examples/http/latent-proxy.js @@ -0,0 +1,54 @@ +/* + latent-proxy.js: Example of proxying over HTTP with latency + + Copyright (c) 2010 Charlie Robbins, Mikeal Rogers, Fedor Indutny, & Marak Squires. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +*/ + +var util = require('util'), + colors = require('colors'), + http = require('http'), + httpProxy = require('../../lib/http-proxy'); + +// +// Http Proxy Server with Latency +// +var proxy = httpProxy.createProxyServer(); +http.createServer(function (req, res) { + setTimeout(function () { + proxy.web(req, res, { + target: 'http://localhost:9000' + }); + }, 500); +}).listen(8000); + +// +// Target Http Server +// +http.createServer(function (req, res) { + res.writeHead(200, { 'Content-Type': 'text/plain' }); + res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2)); + res.end(); +}).listen(9000); + +util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8000 '.yellow + 'with latency'.magenta.underline); +util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow); diff --git a/examples/http/standalone-proxy.js b/examples/http/standalone-proxy.js new file mode 100644 index 000000000..05c440698 --- /dev/null +++ b/examples/http/standalone-proxy.js @@ -0,0 +1,54 @@ +/* + standalone-proxy.js: Example of proxying over HTTP with a standalone HTTP server. + + Copyright (c) 2010 Charlie Robbins, Mikeal Rogers, Fedor Indutny, & Marak Squires. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +*/ + +var util = require('util'), + colors = require('colors'), + http = require('http'), + httpProxy = require('../../lib/http-proxy'); + +// +// Http Server with proxyRequest Handler and Latency +// +var proxy = new httpProxy.createProxyServer(); +http.createServer(function (req, res) { + setTimeout(function () { + proxy.web(req, res, { + target: 'http://localhost:9000' + }); + }, 200); +}).listen(8000); + +// +// Target Http Server +// +http.createServer(function (req, res) { + res.writeHead(200, { 'Content-Type': 'text/plain' }); + res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2)); + res.end(); +}).listen(9000); + +util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '8000 '.yellow + 'with proxy.web() handler'.cyan.underline + ' and latency'.magenta); +util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow); From ed8c9eeba99d60f39f5c36c4f34ed1a781d2cfd8 Mon Sep 17 00:00:00 2001 From: cronopio Date: Tue, 19 Nov 2013 11:42:26 -0500 Subject: [PATCH 06/16] [examples] updated websockets examples --- examples/websocket/latent-websocket-proxy.js | 91 +++++++++++++++++++ .../websocket/standalone-websocket-proxy.js | 88 ++++++++++++++++++ examples/websocket/websocket-proxy.js | 70 ++++++++++++++ 3 files changed, 249 insertions(+) create mode 100644 examples/websocket/latent-websocket-proxy.js create mode 100644 examples/websocket/standalone-websocket-proxy.js create mode 100644 examples/websocket/websocket-proxy.js diff --git a/examples/websocket/latent-websocket-proxy.js b/examples/websocket/latent-websocket-proxy.js new file mode 100644 index 000000000..06569bf5f --- /dev/null +++ b/examples/websocket/latent-websocket-proxy.js @@ -0,0 +1,91 @@ +/* + standalone-websocket-proxy.js: Example of proxying websockets over HTTP with a standalone HTTP server. + + Copyright (c) 2010 Charlie Robbins, Mikeal Rogers, Fedor Indutny, & Marak Squires. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +*/ + +var util = require('util'), + http = require('http'), + colors = require('colors'), + httpProxy = require('../../lib/http-proxy'); + +try { + var io = require('socket.io'), + client = require('socket.io-client'); +} +catch (ex) { + console.error('Socket.io is required for this example:'); + console.error('npm ' + 'install'.green); + process.exit(1); +} + +// +// Create the target HTTP server and setup +// socket.io on it. +// +var server = io.listen(9000); +server.sockets.on('connection', function (client) { + util.debug('Got websocket connection'); + + client.on('message', function (msg) { + util.debug('Got message from client: ' + msg); + }); + + client.send('from server'); +}); + +// +// Setup our server to proxy standard HTTP requests +// +var proxy = new httpProxy.createProxyServer({ + target: { + host: 'localhost', + port: 9000 + } +}); + +var proxyServer = http.createServer(function (req, res) { + proxy.web(req, res); +}); + +// +// Listen to the `upgrade` event and proxy the +// WebSocket requests as well. +// +proxyServer.on('upgrade', function (req, socket, head) { + setTimeout(function () { + proxy.ws(req, socket, head); + }, 1000); +}); + +proxyServer.listen(8000); + +// +// Setup the socket.io client against our proxy +// +var ws = client.connect('ws://localhost:8000'); + +ws.on('message', function (msg) { + util.debug('Got message: ' + msg); + ws.send('I am the client'); +}); diff --git a/examples/websocket/standalone-websocket-proxy.js b/examples/websocket/standalone-websocket-proxy.js new file mode 100644 index 000000000..e844ab097 --- /dev/null +++ b/examples/websocket/standalone-websocket-proxy.js @@ -0,0 +1,88 @@ +/* + standalone-websocket-proxy.js: Example of proxying websockets over HTTP with a standalone HTTP server. + + Copyright (c) 2010 Charlie Robbins, Mikeal Rogers, Fedor Indutny, & Marak Squires. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +*/ + +var util = require('util'), + http = require('http'), + colors = require('colors'), + httpProxy = require('../../lib/http-proxy'); + +try { + var io = require('socket.io'), + client = require('socket.io-client'); +} +catch (ex) { + console.error('Socket.io is required for this example:'); + console.error('npm ' + 'install'.green); + process.exit(1); +} + +// +// Create the target HTTP server and setup +// socket.io on it. +// +var server = io.listen(9000); +server.sockets.on('connection', function (client) { + util.debug('Got websocket connection'); + + client.on('message', function (msg) { + util.debug('Got message from client: ' + msg); + }); + + client.send('from server'); +}); + +// +// Setup our server to proxy standard HTTP requests +// +var proxy = new httpProxy.createProxyServer({ + target: { + host: 'localhost', + port: 9000 + } +}); +var proxyServer = http.createServer(function (req, res) { + proxy.web(req, res); +}); + +// +// Listen to the `upgrade` event and proxy the +// WebSocket requests as well. +// +proxyServer.on('upgrade', function (req, socket, head) { + proxy.ws(req, socket, head); +}); + +proxyServer.listen(8000); + +// +// Setup the socket.io client against our proxy +// +var ws = client.connect('ws://localhost:8000'); + +ws.on('message', function (msg) { + util.debug('Got message: ' + msg); + ws.send('I am the client'); +}); diff --git a/examples/websocket/websocket-proxy.js b/examples/websocket/websocket-proxy.js new file mode 100644 index 000000000..767f58c00 --- /dev/null +++ b/examples/websocket/websocket-proxy.js @@ -0,0 +1,70 @@ +/* + web-socket-proxy.js: Example of proxying over HTTP and WebSockets. + + Copyright (c) 2010 Charlie Robbins, Mikeal Rogers, Fedor Indutny, & Marak Squires. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +*/ + +var util = require('util'), + http = require('http'), + colors = require('colors'), + httpProxy = require('../../lib/http-proxy'); + +try { + var io = require('socket.io'), + client = require('socket.io-client'); +} +catch (ex) { + console.error('Socket.io is required for this example:'); + console.error('npm ' + 'install'.green); + process.exit(1); +} + +// +// Create the target HTTP server and setup +// socket.io on it. +// +var server = io.listen(9000); +server.sockets.on('connection', function (client) { + util.debug('Got websocket connection'); + + client.on('message', function (msg) { + util.debug('Got message from client: ' + msg); + }); + + client.send('from server'); +}); + +// +// Create a proxy server with node-http-proxy +// +httpProxy.createServer({ target: 'ws://localhost:9000', ws: true }).listen(8000); + +// +// Setup the socket.io client against our proxy +// +var ws = client.connect('ws://localhost:8000'); + +ws.on('message', function (msg) { + util.debug('Got message: ' + msg); + ws.send('I am the client'); +}); From 831a44b3c8c3acf6c046c47703a07cd6362a0d1c Mon Sep 17 00:00:00 2001 From: cronopio Date: Tue, 19 Nov 2013 12:13:10 -0500 Subject: [PATCH 07/16] [examples] updated balancer examples --- .../simple-balancer-with-websockets.js | 58 +++++++++++++++++++ examples/balancer/simple-balancer.js | 38 ++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 examples/balancer/simple-balancer-with-websockets.js create mode 100644 examples/balancer/simple-balancer.js diff --git a/examples/balancer/simple-balancer-with-websockets.js b/examples/balancer/simple-balancer-with-websockets.js new file mode 100644 index 000000000..ffe54ec56 --- /dev/null +++ b/examples/balancer/simple-balancer-with-websockets.js @@ -0,0 +1,58 @@ +var http = require('http'), + httpProxy = require('../../lib/http-proxy'); + +// +// A simple round-robin load balancing strategy. +// +// First, list the servers you want to use in your rotation. +// +var addresses = [ + { + host: 'ws1.0.0.0', + port: 80 + }, + { + host: 'ws2.0.0.0', + port: 80 + } +]; + +// +// Create a HttpProxy object for each target +// + +var proxies = addresses.map(function (target) { + return new httpProxy.createProxyServer({ + target: target + }); +}); + +// +// Get the proxy at the front of the array, put it at the end and return it +// If you want a fancier balancer, put your code here +// + +function nextProxy() { + var proxy = proxies.shift(); + proxies.push(proxy); + return proxy; +} + +// +// Get the 'next' proxy and send the http request +// + +var server = http.createServer(function (req, res) { + nextProxy().web(req, res); +}); + +// +// Get the 'next' proxy and send the upgrade request +// + +server.on('upgrade', function (req, socket, head) { + nextProxy().ws(req, socket, head); +}); + +server.listen(8080); + \ No newline at end of file diff --git a/examples/balancer/simple-balancer.js b/examples/balancer/simple-balancer.js new file mode 100644 index 000000000..5660fbc29 --- /dev/null +++ b/examples/balancer/simple-balancer.js @@ -0,0 +1,38 @@ +var http = require('http'), + httpProxy = require('../../lib/http-proxy'); +// +// A simple round-robin load balancing strategy. +// +// First, list the servers you want to use in your rotation. +// +var addresses = [ + { + host: 'ws1.0.0.0', + port: 80 + }, + { + host: 'ws2.0.0.0', + port: 80 + } +]; +var proxy = httpProxy.createServer(); + +http.createServer(function (req, res) { + // + // On each request, get the first location from the list... + // + var target = { target: addresses.shift() }; + + // + // ...then proxy to the server whose 'turn' it is... + // + console.log('balancing request to: ', target); + proxy.web(req, res, target); + + // + // ...and then the server you just used becomes the last item in the list. + // + addresses.push(target); +}).listen(8000); + +// Rinse; repeat; enjoy. \ No newline at end of file From d85ccdd333edcfc7551bcf8e0ffd7dc166e38e61 Mon Sep 17 00:00:00 2001 From: cronopio Date: Tue, 19 Nov 2013 12:38:20 -0500 Subject: [PATCH 08/16] [examples] added package.json with the dependencies needed by examples --- examples/package.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 examples/package.json diff --git a/examples/package.json b/examples/package.json new file mode 100644 index 000000000..be054638e --- /dev/null +++ b/examples/package.json @@ -0,0 +1,10 @@ +{ + "name": "http-proxy-examples", + "description": "packages required to run the examples", + "version": "0.0.0", + "dependencies": { + "colors": "~0.6.2", + "socket.io": "~0.9.16", + "socket.io-client": "~0.9.16" + } +} From e592c53d1a23b7920d603a9e9ac294fc0e841f6d Mon Sep 17 00:00:00 2001 From: cronopio Date: Tue, 19 Nov 2013 19:58:28 -0500 Subject: [PATCH 09/16] [examples] fix the copyright header of example files --- .../simple-balancer-with-websockets.js | 26 +++++++++++++++++++ examples/balancer/simple-balancer.js | 26 +++++++++++++++++++ examples/http/basic-proxy.js | 2 +- examples/http/concurrent-proxy.js | 2 +- examples/http/custom-proxy-error.js | 2 +- examples/http/forward-and-target-proxy.js | 2 +- examples/http/forward-proxy.js | 2 +- examples/http/latent-proxy.js | 2 +- examples/http/proxy-https-to-http.js | 2 +- examples/http/proxy-https-to-https.js | 2 +- examples/http/standalone-proxy.js | 2 +- examples/websocket/latent-websocket-proxy.js | 2 +- .../websocket/standalone-websocket-proxy.js | 2 +- examples/websocket/websocket-proxy.js | 2 +- 14 files changed, 64 insertions(+), 12 deletions(-) diff --git a/examples/balancer/simple-balancer-with-websockets.js b/examples/balancer/simple-balancer-with-websockets.js index ffe54ec56..b17afc772 100644 --- a/examples/balancer/simple-balancer-with-websockets.js +++ b/examples/balancer/simple-balancer-with-websockets.js @@ -1,3 +1,29 @@ +/* + simple-balancer.js: Example of a simple round robin balancer for websockets + + Copyright (c) Nodejitsu 2013 + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +*/ + var http = require('http'), httpProxy = require('../../lib/http-proxy'); diff --git a/examples/balancer/simple-balancer.js b/examples/balancer/simple-balancer.js index 5660fbc29..80b91760c 100644 --- a/examples/balancer/simple-balancer.js +++ b/examples/balancer/simple-balancer.js @@ -1,3 +1,29 @@ +/* + simple-balancer.js: Example of a simple round robin balancer + + Copyright (c) Nodejitsu 2013 + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +*/ + var http = require('http'), httpProxy = require('../../lib/http-proxy'); // diff --git a/examples/http/basic-proxy.js b/examples/http/basic-proxy.js index 8d781604d..640318c11 100644 --- a/examples/http/basic-proxy.js +++ b/examples/http/basic-proxy.js @@ -1,7 +1,7 @@ /* basic-proxy.js: Basic example of proxying over HTTP - Copyright (c) 2010 Charlie Robbins, Mikeal Rogers, Fedor Indutny, & Marak Squires. + Copyright (c) Nodejitsu 2013 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/examples/http/concurrent-proxy.js b/examples/http/concurrent-proxy.js index fd05442e3..5ca1054b8 100644 --- a/examples/http/concurrent-proxy.js +++ b/examples/http/concurrent-proxy.js @@ -1,7 +1,7 @@ /* concurrent-proxy.js: check levelof concurrency through proxy. - Copyright (c) 2010 Charlie Robbins, Mikeal Rogers, Fedor Indutny, & Marak Squires. + Copyright (c) Nodejitsu 2013 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/examples/http/custom-proxy-error.js b/examples/http/custom-proxy-error.js index 5835e881c..dd62273a7 100644 --- a/examples/http/custom-proxy-error.js +++ b/examples/http/custom-proxy-error.js @@ -1,7 +1,7 @@ /* custom-proxy-error.js: Example of using the custom `proxyError` event. - Copyright (c) 2010 Charlie Robbins, Mikeal Rogers, Fedor Indutny, & Marak Squires. + Copyright (c) Nodejitsu 2013 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/examples/http/forward-and-target-proxy.js b/examples/http/forward-and-target-proxy.js index 9ecf4dcec..0d5acd1f6 100644 --- a/examples/http/forward-and-target-proxy.js +++ b/examples/http/forward-and-target-proxy.js @@ -1,7 +1,7 @@ /* forward-and-target-proxy.js: Example of proxying over HTTP with additional forward proxy - Copyright (c) 2010 Charlie Robbins, Mikeal Rogers, Fedor Indutny, & Marak Squires. + Copyright (c) Nodejitsu 2013 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/examples/http/forward-proxy.js b/examples/http/forward-proxy.js index d10a40208..5f93c49f6 100644 --- a/examples/http/forward-proxy.js +++ b/examples/http/forward-proxy.js @@ -1,7 +1,7 @@ /* forward-proxy.js: Example of proxying over HTTP with additional forward proxy - Copyright (c) 2010 Charlie Robbins, Mikeal Rogers, Fedor Indutny, & Marak Squires. + Copyright (c) Nodejitsu 2013 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/examples/http/latent-proxy.js b/examples/http/latent-proxy.js index e2aef9b72..85de6338f 100644 --- a/examples/http/latent-proxy.js +++ b/examples/http/latent-proxy.js @@ -1,7 +1,7 @@ /* latent-proxy.js: Example of proxying over HTTP with latency - Copyright (c) 2010 Charlie Robbins, Mikeal Rogers, Fedor Indutny, & Marak Squires. + Copyright (c) Nodejitsu 2013 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/examples/http/proxy-https-to-http.js b/examples/http/proxy-https-to-http.js index 7c9d1fd93..1b6ac92bd 100644 --- a/examples/http/proxy-https-to-http.js +++ b/examples/http/proxy-https-to-http.js @@ -1,7 +1,7 @@ /* proxy-https-to-http.js: Basic example of proxying over HTTPS to a target HTTP server - Copyright (c) 2010 Charlie Robbins, Mikeal Rogers, Fedor Indutny, & Marak Squires. + Copyright (c) Nodejitsu 2013 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/examples/http/proxy-https-to-https.js b/examples/http/proxy-https-to-https.js index 2ff9151e2..f0d06e8e4 100644 --- a/examples/http/proxy-https-to-https.js +++ b/examples/http/proxy-https-to-https.js @@ -1,7 +1,7 @@ /* proxy-https-to-https.js: Basic example of proxying over HTTPS to a target HTTPS server - Copyright (c) 2010 Charlie Robbins, Mikeal Rogers, Fedor Indutny, & Marak Squires. + Copyright (c) Nodejitsu 2013 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/examples/http/standalone-proxy.js b/examples/http/standalone-proxy.js index 05c440698..7fc97b3d7 100644 --- a/examples/http/standalone-proxy.js +++ b/examples/http/standalone-proxy.js @@ -1,7 +1,7 @@ /* standalone-proxy.js: Example of proxying over HTTP with a standalone HTTP server. - Copyright (c) 2010 Charlie Robbins, Mikeal Rogers, Fedor Indutny, & Marak Squires. + Copyright (c) Nodejitsu 2013 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/examples/websocket/latent-websocket-proxy.js b/examples/websocket/latent-websocket-proxy.js index 06569bf5f..a80a16edd 100644 --- a/examples/websocket/latent-websocket-proxy.js +++ b/examples/websocket/latent-websocket-proxy.js @@ -1,7 +1,7 @@ /* standalone-websocket-proxy.js: Example of proxying websockets over HTTP with a standalone HTTP server. - Copyright (c) 2010 Charlie Robbins, Mikeal Rogers, Fedor Indutny, & Marak Squires. + Copyright (c) Nodejitsu 2013 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/examples/websocket/standalone-websocket-proxy.js b/examples/websocket/standalone-websocket-proxy.js index e844ab097..a78ecedbc 100644 --- a/examples/websocket/standalone-websocket-proxy.js +++ b/examples/websocket/standalone-websocket-proxy.js @@ -1,7 +1,7 @@ /* standalone-websocket-proxy.js: Example of proxying websockets over HTTP with a standalone HTTP server. - Copyright (c) 2010 Charlie Robbins, Mikeal Rogers, Fedor Indutny, & Marak Squires. + Copyright (c) Nodejitsu 2013 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/examples/websocket/websocket-proxy.js b/examples/websocket/websocket-proxy.js index 767f58c00..dfd46e064 100644 --- a/examples/websocket/websocket-proxy.js +++ b/examples/websocket/websocket-proxy.js @@ -1,7 +1,7 @@ /* web-socket-proxy.js: Example of proxying over HTTP and WebSockets. - Copyright (c) 2010 Charlie Robbins, Mikeal Rogers, Fedor Indutny, & Marak Squires. + Copyright (c) Nodejitsu 2013 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the From 2142c506e08f56d52e1995da5506c3e032f19c3c Mon Sep 17 00:00:00 2001 From: cronopio Date: Wed, 27 Nov 2013 09:42:56 -0500 Subject: [PATCH 10/16] [examples] add example of gzip using the connect.compress() middleware --- examples/middleware/gzip-middleware.js | 65 ++++++++++++++++++++++++++ examples/package.json | 3 +- 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 examples/middleware/gzip-middleware.js diff --git a/examples/middleware/gzip-middleware.js b/examples/middleware/gzip-middleware.js new file mode 100644 index 000000000..ec8725940 --- /dev/null +++ b/examples/middleware/gzip-middleware.js @@ -0,0 +1,65 @@ +/* + gzip-middleware.js: Basic example of `connect-gzip` middleware in node-http-proxy + + Copyright (c) Nodejitsu 2013 + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +*/ + +var util = require('util'), + colors = require('colors'), + http = require('http'), + connect = require('connect') + httpProxy = require('../../lib/http-proxy'); + +// +// Basic Connect App +// +connect.createServer( + connect.compress({ + // Pass to connect.compress() the options + // that you need, just for show the example + // we use threshold to 1 + threshold: 1 + }), + function (req, res) { + proxy.web(req, res); + } +).listen(8000); + +// +// Basic HTTP Proxy +// +var proxy = httpProxy.createProxyServer({ + target: 'http://localhost:9000' +}); + +// +// Target Http Server +// +http.createServer(function (req, res) { + res.writeHead(200, { 'Content-Type': 'text/plain' }); + res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2)); + res.end(); +}).listen(9000); + +util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow); +util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow); diff --git a/examples/package.json b/examples/package.json index be054638e..7db2ae68a 100644 --- a/examples/package.json +++ b/examples/package.json @@ -5,6 +5,7 @@ "dependencies": { "colors": "~0.6.2", "socket.io": "~0.9.16", - "socket.io-client": "~0.9.16" + "socket.io-client": "~0.9.16", + "connect": "~2.11.0" } } From de3ff11656b4a847de3a63b28feed39b6c816480 Mon Sep 17 00:00:00 2001 From: cronopio Date: Wed, 27 Nov 2013 09:56:35 -0500 Subject: [PATCH 11/16] [examples] updated the modifyResponse-middleware example --- examples/middleware/gzip-middleware.js | 2 +- .../middleware/modifyResponse-middleware.js | 67 +++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 examples/middleware/modifyResponse-middleware.js diff --git a/examples/middleware/gzip-middleware.js b/examples/middleware/gzip-middleware.js index ec8725940..ee32e445b 100644 --- a/examples/middleware/gzip-middleware.js +++ b/examples/middleware/gzip-middleware.js @@ -46,7 +46,7 @@ connect.createServer( ).listen(8000); // -// Basic HTTP Proxy +// Basic Http Proxy Server // var proxy = httpProxy.createProxyServer({ target: 'http://localhost:9000' diff --git a/examples/middleware/modifyResponse-middleware.js b/examples/middleware/modifyResponse-middleware.js new file mode 100644 index 000000000..c4a59a2f0 --- /dev/null +++ b/examples/middleware/modifyResponse-middleware.js @@ -0,0 +1,67 @@ +/* + modifyBody-middleware.js: Example of middleware which modifies response + + Copyright (c) Nodejitsu 2013 + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +*/ + +var util = require('util'), + colors = require('colors'), + http = require('http'), + connect = require('connect'), + httpProxy = require('../../lib/http-proxy'); + +// +// Basic Connect App +// +connect.createServer( + function (req, res, next) { + var _write = res.write; + + res.write = function (data) { + _write.call(res, data.toString().replace("Ruby", "nodejitsu")); + } + next(); + }, + function (req, res) { + proxy.web(req, res); + } +).listen(8000); + +// +// Basic Http Proxy Server +// +var proxy = httpProxy.createProxyServer({ + target: 'http://localhost:9000' +}); + +// +// Target Http Server +// +http.createServer(function (req, res) { + res.writeHead(200, { 'Content-Type': 'text/plain' }); + res.end('Hello, I know Ruby\n'); +}).listen(9000); + +util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow); +util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow); + From d7064f2e1e149fe870cbb158932cb99f9f192fce Mon Sep 17 00:00:00 2001 From: cronopio Date: Wed, 27 Nov 2013 16:35:38 -0500 Subject: [PATCH 12/16] [examples] added error-handling using callbacks and HTTP-to-HTTPS examples --- examples/http/error-handling.js | 63 ++++++++++++++++++++++++++++ examples/http/proxy-http-to-https.js | 46 ++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 examples/http/error-handling.js create mode 100644 examples/http/proxy-http-to-https.js diff --git a/examples/http/error-handling.js b/examples/http/error-handling.js new file mode 100644 index 000000000..292fb6144 --- /dev/null +++ b/examples/http/error-handling.js @@ -0,0 +1,63 @@ +/* + error-handling.js: Example of handle erros for HTTP and WebSockets + + Copyright (c) Nodejitsu 2013 + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +*/ + +var util = require('util'), + colors = require('colors'), + http = require('http'), + httpProxy = require('../../lib/http-proxy'); + +// +// HTTP Proxy Server +// +var proxy = httpProxy.createProxyServer({target:'http://localhost:9000', ws:true}); + +// +// Example of error handling +// +function requestHandler(req, res) { + // Pass a callback to the web proxy method + // and catch the error there. + proxy.web(req, res, function (err) { + // Now you can get the err + // and handle it by your self + // if (err) throw err; + res.writeHead(502); + res.end("There was an error proxying your request"); + }); + + // In a websocket request case + req.on('upgrade', function (req, socket, head) { + proxy.ws(req, socket, head, function (err) { + // Now you can get the err + // and handle it by your self + // if (err) throw err; + socket.close(); + }) + }) +} + +http.createServer(requestHandler).listen(8000); +util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow); diff --git a/examples/http/proxy-http-to-https.js b/examples/http/proxy-http-to-https.js new file mode 100644 index 000000000..ffaa6fa04 --- /dev/null +++ b/examples/http/proxy-http-to-https.js @@ -0,0 +1,46 @@ +/* + proxy-http-to-https.js: Basic example of proxying over HTTP to a target HTTPS server + + Copyright (c) Nodejitsu 2013 + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +*/ + +var https = require('https'), + http = require('http'), + util = require('util'), + path = require('path'), + fs = require('fs'), + colors = require('colors'), + httpProxy = require('../../lib/http-proxy'); + +// +// Create a HTTP Proxy server with a HTTPS target +// +httpProxy.createProxyServer({ + target: 'https://google.com', + agent : https.globalAgent, + headers: { + host: 'google.com' + } +}).listen(8000); + +util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow); \ No newline at end of file From c82ff2c3c0c0165421fbc4e7e94fa3f59d59aa38 Mon Sep 17 00:00:00 2001 From: cronopio Date: Wed, 27 Nov 2013 17:02:06 -0500 Subject: [PATCH 13/16] [examples] updated bodyDecoder middleware example --- examples/helpers/store.js | 64 ++++++++++ examples/middleware/bodyDecoder-middleware.js | 119 ++++++++++++++++++ examples/package.json | 4 +- 3 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 examples/helpers/store.js create mode 100644 examples/middleware/bodyDecoder-middleware.js diff --git a/examples/helpers/store.js b/examples/helpers/store.js new file mode 100644 index 000000000..e2860573f --- /dev/null +++ b/examples/helpers/store.js @@ -0,0 +1,64 @@ + +// +// just to make these example a little bit interesting, +// make a little key value store with an http interface +// (see couchbd for a grown-up version of this) +// +// API: +// GET / +// retrive list of keys +// +// GET /[url] +// retrive object stored at [url] +// will respond with 404 if there is nothing stored at [url] +// +// POST /[url] +// +// JSON.parse the body and store it under [url] +// will respond 400 (bad request) if body is not valid json. +// +// TODO: cached map-reduce views and auto-magic sharding. +// +var Store = module.exports = function Store () { + this.store = {}; +}; + +Store.prototype = { + get: function (key) { + return this.store[key] + }, + set: function (key, value) { + return this.store[key] = value + }, + handler:function () { + var store = this + return function (req, res) { + function send (obj, status) { + res.writeHead(200 || status,{'Content-Type': 'application/json'}) + res.write(JSON.stringify(obj) + '\n') + res.end() + } + var url = req.url.split('?').shift() + if (url === '/') { + console.log('get index') + return send(Object.keys(store.store)) + } else if (req.method == 'GET') { + var obj = store.get (url) + send(obj || {error: 'not_found', url: url}, obj ? 200 : 404) + } else { + //post: buffer body, and parse. + var body = '', obj + req.on('data', function (c) { body += c}) + req.on('end', function (c) { + try { + obj = JSON.parse(body) + } catch (err) { + return send (err, 400) + } + store.set(url, obj) + send({ok: true}) + }) + } + } + } +} diff --git a/examples/middleware/bodyDecoder-middleware.js b/examples/middleware/bodyDecoder-middleware.js new file mode 100644 index 000000000..555c3d154 --- /dev/null +++ b/examples/middleware/bodyDecoder-middleware.js @@ -0,0 +1,119 @@ +/* + bodyDecoder-middleware.js: Basic example of `connect.bodyParser()` middleware in node-http-proxy + + Copyright (c) Nodejitsu 2013 + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +*/ + +var http = require('http'), + connect = require('connect'), + request = require('request'), + colors = require('colors'), + util = require('util'), + Store = require('../helpers/store'), + httpProxy = require('../../lib/http-proxy'), + proxy = httpProxy.createProxyServer({}); + +http.createServer(new Store().handler()).listen(7531, function () { + util.puts('http '.blue + 'greetings '.green + 'server'.blue + ' started '.green.bold + 'on port '.blue + '7531'.yellow); +//try these commands: +// get index: +// curl localhost:7531 +// [] +// +// get a doc: +// curl localhost:7531/foo +// {"error":"not_found"} +// +// post an doc: +// curl -X POST localhost:7531/foo -d '{"content": "hello", "type": "greeting"}' +// {"ok":true} +// +// get index (now, not empty) +// curl localhost:7531 +// ["/foo"] +// +// get doc +// curl localhost:7531/foo +// {"content": "hello", "type": "greeting"} + +// +// now, suppose we wanted to direct all objects where type == "greeting" to a different store +// than where type == "insult" +// +// we can use connect connect-bodyDecoder and some custom logic to send insults to another Store. + +//insult server: + + http.createServer(new Store().handler()).listen(2600, function () { + util.puts('http '.blue + 'insults '.red + 'server'.blue + ' started '.green.bold + 'on port '.blue + '2600'.yellow); + + //greetings -> 7531, insults-> 2600 + + // now, start a proxy server. + + //don't worry about incoming contont type + //bodyParser.parse[''] = JSON.parse + + connect.createServer( + //refactor the body parser and re-streamer into a separate package + connect.bodyParser(), + //body parser absorbs the data and end events before passing control to the next + // middleware. if we want to proxy it, we'll need to re-emit these events after + //passing control to the middleware. + require('connect-restreamer')(), + function (req, res) { + //if your posting an obect which contains type: "insult" + //it will get redirected to port 2600. + //normal get requests will go to 7531 nad will not return insults. + var port = (req.body && req.body.type === 'insult' ? 2600 : 7531) + proxy.web(req, res, { target: { host: 'localhost', port: port }}); + } + ).listen(1337, function () { + util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '1337'.yellow); + //bodyParser needs content-type set to application/json + //if we use request, it will set automatically if we use the 'json:' field. + function post (greeting, type) { + request.post({ + url: 'http://localhost:1337/' + greeting, + json: {content: greeting, type: type || "greeting"} + }) + } + post("hello") + post("g'day") + post("kiora") + post("houdy") + post("java", "insult") + + //now, the insult should have been proxied to 2600 + + //curl localhost:2600 + //["/java"] + + //but the greetings will be sent to 7531 + + //curl localhost:7531 + //["/hello","/g%27day","/kiora","/houdy"] + + }) + }) +}); \ No newline at end of file diff --git a/examples/package.json b/examples/package.json index 7db2ae68a..3daede1f1 100644 --- a/examples/package.json +++ b/examples/package.json @@ -6,6 +6,8 @@ "colors": "~0.6.2", "socket.io": "~0.9.16", "socket.io-client": "~0.9.16", - "connect": "~2.11.0" + "connect": "~2.11.0", + "request": "~2.27.0", + "connect-restreamer": "~1.0.0" } } From bc236d7e95ef10bc17cf551eea2cd2fb9bf265eb Mon Sep 17 00:00:00 2001 From: cronopio Date: Wed, 27 Nov 2013 17:58:00 -0500 Subject: [PATCH 14/16] [tests] Added a test case for run all the examples * I changed all the ports across examples to be different and can run at same time --- .../simple-balancer-with-websockets.js | 2 +- examples/balancer/simple-balancer.js | 2 +- examples/http/basic-proxy.js | 10 +-- examples/http/concurrent-proxy.js | 10 +-- examples/http/custom-proxy-error.js | 6 +- examples/http/forward-and-target-proxy.js | 16 ++--- examples/http/forward-proxy.js | 10 +-- examples/http/latent-proxy.js | 10 +-- examples/http/proxy-http-to-https.js | 4 +- examples/http/proxy-https-to-http.js | 10 +-- examples/http/proxy-https-to-https.js | 10 +-- examples/http/standalone-proxy.js | 10 +-- examples/middleware/gzip-middleware.js | 10 +-- .../middleware/modifyResponse-middleware.js | 10 +-- examples/websocket/latent-websocket-proxy.js | 8 +-- .../websocket/standalone-websocket-proxy.js | 8 +-- examples/websocket/websocket-proxy.js | 6 +- package.json | 3 +- test/examples-test.js | 71 +++++++++++++++++++ 19 files changed, 144 insertions(+), 72 deletions(-) create mode 100644 test/examples-test.js diff --git a/examples/balancer/simple-balancer-with-websockets.js b/examples/balancer/simple-balancer-with-websockets.js index b17afc772..cc13f4b5c 100644 --- a/examples/balancer/simple-balancer-with-websockets.js +++ b/examples/balancer/simple-balancer-with-websockets.js @@ -80,5 +80,5 @@ server.on('upgrade', function (req, socket, head) { nextProxy().ws(req, socket, head); }); -server.listen(8080); +server.listen(8001); \ No newline at end of file diff --git a/examples/balancer/simple-balancer.js b/examples/balancer/simple-balancer.js index 80b91760c..3f53cc63d 100644 --- a/examples/balancer/simple-balancer.js +++ b/examples/balancer/simple-balancer.js @@ -59,6 +59,6 @@ http.createServer(function (req, res) { // ...and then the server you just used becomes the last item in the list. // addresses.push(target); -}).listen(8000); +}).listen(8021); // Rinse; repeat; enjoy. \ No newline at end of file diff --git a/examples/http/basic-proxy.js b/examples/http/basic-proxy.js index 640318c11..e9be0d79b 100644 --- a/examples/http/basic-proxy.js +++ b/examples/http/basic-proxy.js @@ -44,8 +44,8 @@ util.puts(welcome.rainbow.bold); // Basic Http Proxy Server // httpProxy.createServer({ - target:'http://localhost:9000' -}).listen(8000); + target:'http://localhost:9003' +}).listen(8003); // // Target Http Server @@ -54,7 +54,7 @@ http.createServer(function (req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2)); res.end(); -}).listen(9000); +}).listen(9003); -util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow); -util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow); +util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8003'.yellow); +util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9003 '.yellow); diff --git a/examples/http/concurrent-proxy.js b/examples/http/concurrent-proxy.js index 5ca1054b8..30aa53dd6 100644 --- a/examples/http/concurrent-proxy.js +++ b/examples/http/concurrent-proxy.js @@ -33,8 +33,8 @@ var util = require('util'), // Basic Http Proxy Server // httpProxy.createServer({ - target:'http://localhost:9000' -}).listen(8000); + target:'http://localhost:9004' +}).listen(8004); // // Target Http Server @@ -62,7 +62,7 @@ http.createServer(function (req, res) { connections.shift()(); } } -}).listen(9000); +}).listen(9004); -util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow); -util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow); +util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8004'.yellow); +util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9004 '.yellow); diff --git a/examples/http/custom-proxy-error.js b/examples/http/custom-proxy-error.js index dd62273a7..1c54b5ab8 100644 --- a/examples/http/custom-proxy-error.js +++ b/examples/http/custom-proxy-error.js @@ -33,13 +33,13 @@ var util = require('util'), // Http Proxy Server with bad target // var proxy = httpProxy.createServer({ - target:'http://localhost:9000' + target:'http://localhost:9005' }); // // Tell the proxy to listen on port 8000 // -proxy.listen(8000); +proxy.listen(8005); // // Listen for the `error` event on `proxy`. @@ -52,4 +52,4 @@ proxy.on('error', function (err, req, res) { }); -util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8000 '.yellow + 'with custom error message'.magenta.underline); \ No newline at end of file +util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8005 '.yellow + 'with custom error message'.magenta.underline); \ No newline at end of file diff --git a/examples/http/forward-and-target-proxy.js b/examples/http/forward-and-target-proxy.js index 0d5acd1f6..c564bfbbd 100644 --- a/examples/http/forward-and-target-proxy.js +++ b/examples/http/forward-and-target-proxy.js @@ -34,14 +34,14 @@ var util = require('util'), // httpProxy.createServer({ target: { - port: 9000, + port: 9006, host: 'localhost' }, forward: { - port: 9001, + port: 9007, host: 'localhost' } -}).listen(8000); +}).listen(8006); // // Target Http Server @@ -50,7 +50,7 @@ http.createServer(function (req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2)); res.end(); -}).listen(9000); +}).listen(9006); // // Target Http Forwarding Server @@ -60,8 +60,8 @@ http.createServer(function (req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.write('request successfully forwarded to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2)); res.end(); -}).listen(9001); +}).listen(9007); -util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8000 '.yellow + 'with forward proxy'.magenta.underline); -util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow); -util.puts('http forward server '.blue + 'started '.green.bold + 'on port '.blue + '9001 '.yellow); \ No newline at end of file +util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8006 '.yellow + 'with forward proxy'.magenta.underline); +util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9006 '.yellow); +util.puts('http forward server '.blue + 'started '.green.bold + 'on port '.blue + '9007 '.yellow); \ No newline at end of file diff --git a/examples/http/forward-proxy.js b/examples/http/forward-proxy.js index 5f93c49f6..d94f48414 100644 --- a/examples/http/forward-proxy.js +++ b/examples/http/forward-proxy.js @@ -34,10 +34,10 @@ var util = require('util'), // httpProxy.createServer({ forward: { - port: 9000, + port: 9019, host: 'localhost' } -}).listen(8000); +}).listen(8019); // // Target Http Forwarding Server @@ -47,7 +47,7 @@ http.createServer(function (req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.write('request successfully forwarded to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2)); res.end(); -}).listen(9000); +}).listen(9019); -util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8000 '.yellow + 'with forward proxy'.magenta.underline); -util.puts('http forward server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow); \ No newline at end of file +util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8019 '.yellow + 'with forward proxy'.magenta.underline); +util.puts('http forward server '.blue + 'started '.green.bold + 'on port '.blue + '9019 '.yellow); \ No newline at end of file diff --git a/examples/http/latent-proxy.js b/examples/http/latent-proxy.js index 85de6338f..01ec93cc7 100644 --- a/examples/http/latent-proxy.js +++ b/examples/http/latent-proxy.js @@ -36,10 +36,10 @@ var proxy = httpProxy.createProxyServer(); http.createServer(function (req, res) { setTimeout(function () { proxy.web(req, res, { - target: 'http://localhost:9000' + target: 'http://localhost:9008' }); }, 500); -}).listen(8000); +}).listen(8008); // // Target Http Server @@ -48,7 +48,7 @@ http.createServer(function (req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2)); res.end(); -}).listen(9000); +}).listen(9008); -util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8000 '.yellow + 'with latency'.magenta.underline); -util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow); +util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8008 '.yellow + 'with latency'.magenta.underline); +util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9008 '.yellow); diff --git a/examples/http/proxy-http-to-https.js b/examples/http/proxy-http-to-https.js index ffaa6fa04..ba5c83816 100644 --- a/examples/http/proxy-http-to-https.js +++ b/examples/http/proxy-http-to-https.js @@ -41,6 +41,6 @@ httpProxy.createProxyServer({ headers: { host: 'google.com' } -}).listen(8000); +}).listen(8011); -util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow); \ No newline at end of file +util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8011'.yellow); \ No newline at end of file diff --git a/examples/http/proxy-https-to-http.js b/examples/http/proxy-https-to-http.js index 1b6ac92bd..d2a2d5c0d 100644 --- a/examples/http/proxy-https-to-http.js +++ b/examples/http/proxy-https-to-http.js @@ -40,7 +40,7 @@ http.createServer(function (req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.write('hello http over https\n'); res.end(); -}).listen(9000); +}).listen(9009); // // Create the HTTPS proxy server listening on port 8000 @@ -48,13 +48,13 @@ http.createServer(function (req, res) { httpProxy.createServer({ target: { host: 'localhost', - port: 9000 + port: 9009 }, ssl: { key: fs.readFileSync(path.join(fixturesDir, 'agent2-key.pem'), 'utf8'), cert: fs.readFileSync(path.join(fixturesDir, 'agent2-cert.pem'), 'utf8') } -}).listen(8000); +}).listen(8009); -util.puts('https proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow); -util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow); +util.puts('https proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8009'.yellow); +util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9009 '.yellow); diff --git a/examples/http/proxy-https-to-https.js b/examples/http/proxy-https-to-https.js index f0d06e8e4..e543f98a7 100644 --- a/examples/http/proxy-https-to-https.js +++ b/examples/http/proxy-https-to-https.js @@ -44,16 +44,16 @@ https.createServer(httpsOpts, function (req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.write('hello https\n'); res.end(); -}).listen(9000); +}).listen(9010); // // Create the proxy server listening on port 443 // httpProxy.createServer({ ssl: httpsOpts, - target: 'https://localhost:9000', + target: 'https://localhost:9010', secure: false -}).listen(8000); +}).listen(8010); -util.puts('https proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow); -util.puts('https server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow); +util.puts('https proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8010'.yellow); +util.puts('https server '.blue + 'started '.green.bold + 'on port '.blue + '9010 '.yellow); diff --git a/examples/http/standalone-proxy.js b/examples/http/standalone-proxy.js index 7fc97b3d7..410d70b31 100644 --- a/examples/http/standalone-proxy.js +++ b/examples/http/standalone-proxy.js @@ -36,10 +36,10 @@ var proxy = new httpProxy.createProxyServer(); http.createServer(function (req, res) { setTimeout(function () { proxy.web(req, res, { - target: 'http://localhost:9000' + target: 'http://localhost:9002' }); }, 200); -}).listen(8000); +}).listen(8002); // // Target Http Server @@ -48,7 +48,7 @@ http.createServer(function (req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2)); res.end(); -}).listen(9000); +}).listen(9002); -util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '8000 '.yellow + 'with proxy.web() handler'.cyan.underline + ' and latency'.magenta); -util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow); +util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '8002 '.yellow + 'with proxy.web() handler'.cyan.underline + ' and latency'.magenta); +util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9001 '.yellow); diff --git a/examples/middleware/gzip-middleware.js b/examples/middleware/gzip-middleware.js index ee32e445b..756b68fa3 100644 --- a/examples/middleware/gzip-middleware.js +++ b/examples/middleware/gzip-middleware.js @@ -43,13 +43,13 @@ connect.createServer( function (req, res) { proxy.web(req, res); } -).listen(8000); +).listen(8012); // // Basic Http Proxy Server // var proxy = httpProxy.createProxyServer({ - target: 'http://localhost:9000' + target: 'http://localhost:9012' }); // @@ -59,7 +59,7 @@ http.createServer(function (req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2)); res.end(); -}).listen(9000); +}).listen(9012); -util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow); -util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow); +util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8012'.yellow); +util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9012 '.yellow); diff --git a/examples/middleware/modifyResponse-middleware.js b/examples/middleware/modifyResponse-middleware.js index c4a59a2f0..fdd7e6596 100644 --- a/examples/middleware/modifyResponse-middleware.js +++ b/examples/middleware/modifyResponse-middleware.js @@ -45,13 +45,13 @@ connect.createServer( function (req, res) { proxy.web(req, res); } -).listen(8000); +).listen(8013); // // Basic Http Proxy Server // var proxy = httpProxy.createProxyServer({ - target: 'http://localhost:9000' + target: 'http://localhost:9013' }); // @@ -60,8 +60,8 @@ var proxy = httpProxy.createProxyServer({ http.createServer(function (req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Hello, I know Ruby\n'); -}).listen(9000); +}).listen(9013); -util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow); -util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow); +util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8013'.yellow); +util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9013 '.yellow); diff --git a/examples/websocket/latent-websocket-proxy.js b/examples/websocket/latent-websocket-proxy.js index a80a16edd..64d3d7ce0 100644 --- a/examples/websocket/latent-websocket-proxy.js +++ b/examples/websocket/latent-websocket-proxy.js @@ -43,7 +43,7 @@ catch (ex) { // Create the target HTTP server and setup // socket.io on it. // -var server = io.listen(9000); +var server = io.listen(9016); server.sockets.on('connection', function (client) { util.debug('Got websocket connection'); @@ -60,7 +60,7 @@ server.sockets.on('connection', function (client) { var proxy = new httpProxy.createProxyServer({ target: { host: 'localhost', - port: 9000 + port: 9016 } }); @@ -78,12 +78,12 @@ proxyServer.on('upgrade', function (req, socket, head) { }, 1000); }); -proxyServer.listen(8000); +proxyServer.listen(8016); // // Setup the socket.io client against our proxy // -var ws = client.connect('ws://localhost:8000'); +var ws = client.connect('ws://localhost:8016'); ws.on('message', function (msg) { util.debug('Got message: ' + msg); diff --git a/examples/websocket/standalone-websocket-proxy.js b/examples/websocket/standalone-websocket-proxy.js index a78ecedbc..81d019650 100644 --- a/examples/websocket/standalone-websocket-proxy.js +++ b/examples/websocket/standalone-websocket-proxy.js @@ -43,7 +43,7 @@ catch (ex) { // Create the target HTTP server and setup // socket.io on it. // -var server = io.listen(9000); +var server = io.listen(9015); server.sockets.on('connection', function (client) { util.debug('Got websocket connection'); @@ -60,7 +60,7 @@ server.sockets.on('connection', function (client) { var proxy = new httpProxy.createProxyServer({ target: { host: 'localhost', - port: 9000 + port: 9015 } }); var proxyServer = http.createServer(function (req, res) { @@ -75,12 +75,12 @@ proxyServer.on('upgrade', function (req, socket, head) { proxy.ws(req, socket, head); }); -proxyServer.listen(8000); +proxyServer.listen(8015); // // Setup the socket.io client against our proxy // -var ws = client.connect('ws://localhost:8000'); +var ws = client.connect('ws://localhost:8015'); ws.on('message', function (msg) { util.debug('Got message: ' + msg); diff --git a/examples/websocket/websocket-proxy.js b/examples/websocket/websocket-proxy.js index dfd46e064..33d78c675 100644 --- a/examples/websocket/websocket-proxy.js +++ b/examples/websocket/websocket-proxy.js @@ -43,7 +43,7 @@ catch (ex) { // Create the target HTTP server and setup // socket.io on it. // -var server = io.listen(9000); +var server = io.listen(9014); server.sockets.on('connection', function (client) { util.debug('Got websocket connection'); @@ -57,12 +57,12 @@ server.sockets.on('connection', function (client) { // // Create a proxy server with node-http-proxy // -httpProxy.createServer({ target: 'ws://localhost:9000', ws: true }).listen(8000); +httpProxy.createServer({ target: 'ws://localhost:9014', ws: true }).listen(8014); // // Setup the socket.io client against our proxy // -var ws = client.connect('ws://localhost:8000'); +var ws = client.connect('ws://localhost:8014'); ws.on('message', function (msg) { util.debug('Got message: ' + msg); diff --git a/package.json b/package.json index 98cd9b5d4..5c7c3a1eb 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "blanket" : "*", "ws" : "*", "socket.io" : "*", - "socket.io-client" : "*" + "socket.io-client" : "*", + "async" : "*" }, "scripts" : { "coveralls" : "mocha --require blanket --reporter mocha-lcov-reporter | ./node_modules/coveralls/bin/coveralls.js", diff --git a/test/examples-test.js b/test/examples-test.js new file mode 100644 index 000000000..234587bcb --- /dev/null +++ b/test/examples-test.js @@ -0,0 +1,71 @@ +/* + examples-test.js: Test to run all the examples + + Copyright (c) Nodejitsu 2013 + +*/ +var path = require('path'), + fs = require('fs'), + spawn = require('child_process').spawn, + expect = require('expect.js'), + async = require('async'); + +var rootDir = path.join(__dirname, '..'), + examplesDir = path.join(rootDir, 'examples'); + +describe('http-proxy examples', function () { + describe('Before testing examples', function () { + // Set a timeout to avoid this error + this.timeout(30 * 1000); + it('should have installed dependencies', function (done) { + async.waterfall([ + // + // 1. Read files in examples dir + // + async.apply(fs.readdir, examplesDir), + // + // 2. If node_modules exists, continue. Otherwise + // exec `npm` to install them + // + function checkNodeModules(files, next) { + if (files.indexOf('node_modules') !== -1) { + return next(); + } + + console.log('Warning: installing dependencies, this operation could take a while'); + + var child = spawn('npm', ['install', '-f'], { + cwd: examplesDir + }); + + child.on('exit', function (code) { + return code + ? next(new Error('npm install exited with non-zero exit code')) + : next(); + }); + }, + // + // 3. Read files in examples dir again to ensure the install + // worked as expected. + // + async.apply(fs.readdir, examplesDir), + ], done); + }) + }); + + describe('Requiring all the examples', function () { + it('should have no errors', function (done) { + async.each(['balancer', 'http', 'middleware', 'websocket'], function (dir, cb) { + var name = 'examples/' + dir, + files = fs.readdirSync(path.join(rootDir, 'examples', dir)); + + async.each(files, function (file, callback) { + var example; + expect(function () { example = require(path.join(examplesDir, dir, file)); }).to.not.throwException(); + expect(example).to.be.an('object'); + callback(); + }, cb); + }, done); + }) + }) +}) \ No newline at end of file From d83fdf69a1121bfcfba72bbffcd3105ae5852c56 Mon Sep 17 00:00:00 2001 From: cronopio Date: Mon, 9 Dec 2013 12:34:28 -0500 Subject: [PATCH 15/16] [tests] disabled the examples-test by now --- test/examples-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/examples-test.js b/test/examples-test.js index 234587bcb..8464e3fe5 100644 --- a/test/examples-test.js +++ b/test/examples-test.js @@ -13,7 +13,7 @@ var path = require('path'), var rootDir = path.join(__dirname, '..'), examplesDir = path.join(rootDir, 'examples'); -describe('http-proxy examples', function () { +describe.skip('http-proxy examples', function () { describe('Before testing examples', function () { // Set a timeout to avoid this error this.timeout(30 * 1000); From e2a5d513cac3ebceff446787fa106c7f00caf785 Mon Sep 17 00:00:00 2001 From: cronopio Date: Wed, 18 Dec 2013 11:19:17 -0500 Subject: [PATCH 16/16] Set travis to run `npm test` while we fix coveralss.io integration --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d7eeacc3f..ba5be4174 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,4 +9,4 @@ notifications: irc: "irc.freenode.org#nodejitsu" script: - npm run-script coveralls + npm test