diff --git a/examples/helpers/store.js b/examples/helpers/store.js index 8144b13b6..62a627e41 100644 --- a/examples/helpers/store.js +++ b/examples/helpers/store.js @@ -1,5 +1,4 @@ -module.exports = Store // // just to make these example a little bit interesting, // make a little key value store with an http interface @@ -20,12 +19,10 @@ module.exports = Store // // TODO: cached map-reduce views and auto-magic sharding. // +var Store = module.exports = function Store () { + this.store = {}; +}; - - -function Store () { - this.store = {} -} Store.prototype = { get: function (key) { return this.store[key] diff --git a/examples/http/basic-proxy.js b/examples/http/basic-proxy.js index 58276251c..b890e69a0 100644 --- a/examples/http/basic-proxy.js +++ b/examples/http/basic-proxy.js @@ -27,16 +27,17 @@ var util = require('util'), colors = require('colors'), http = require('http'), - httpProxy = require('./../lib/node-http-proxy'); - -// ascii art from http://github.com/marak/asciimo -var welcome = '\ -# # ##### ##### ##### ##### ##### #### # # # # \n\ -# # # # # # # # # # # # # # # # \n\ -###### # # # # ##### # # # # # # ## # \n\ -# # # # ##### ##### ##### # # ## # \n\ -# # # # # # # # # # # # # \n\ -# # # # # # # # #### # # # \n'; + httpProxy = require('../../lib/node-http-proxy'); + +var welcome = [ + '# # ##### ##### ##### ##### ##### #### # # # #', + '# # # # # # # # # # # # # # # # ', + '###### # # # # ##### # # # # # # ## # ', + '# # # # ##### ##### ##### # # ## # ', + '# # # # # # # # # # # # # ', + '# # # # # # # # #### # # # ' +].join('\n'); + util.puts(welcome.rainbow.bold); // diff --git a/examples/http/concurrent-proxy.js b/examples/http/concurrent-proxy.js index 4bf5673fe..230dfc651 100644 --- a/examples/http/concurrent-proxy.js +++ b/examples/http/concurrent-proxy.js @@ -27,7 +27,7 @@ var util = require('util'), colors = require('colors'), http = require('http'), - httpProxy = require('./../lib/node-http-proxy'); + httpProxy = require('../../lib/node-http-proxy'); // // Basic Http Proxy Server @@ -42,23 +42,24 @@ httpProxy.createServer(9000, 'localhost').listen(8000); // -var connections = [] - , go +var connections = [], + go; http.createServer(function (req, res) { - - connections.push (function (){ + 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 + ', ') + }); + + process.stdout.write(connections.length + ', '); + if (connections.length > 110 || go) { - go = true - while(connections.length) - connections.shift()() + go = true; + while (connections.length) { + connections.shift()(); + } } - }).listen(9000); util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow); diff --git a/examples/http/custom-proxy-error.js b/examples/http/custom-proxy-error.js index 0fd90adf3..dc439ea19 100644 --- a/examples/http/custom-proxy-error.js +++ b/examples/http/custom-proxy-error.js @@ -27,17 +27,12 @@ var util = require('util'), colors = require('colors'), http = require('http'), - httpProxy = require('./../lib/node-http-proxy'); + httpProxy = require('../../lib/node-http-proxy'); // // Http Proxy Server with Latency // -var server = httpProxy.createServer(function (req, res, proxy) { - proxy.proxyRequest(req, res, { - port: 9000, - host: 'localhost' - }); -}) +var server = httpProxy.createServer(9000, 'localhost'); // // Tell the server to listen on port 8002 diff --git a/examples/http/forward-proxy.js b/examples/http/forward-proxy.js index 667d67250..ecc20fd4c 100644 --- a/examples/http/forward-proxy.js +++ b/examples/http/forward-proxy.js @@ -27,7 +27,7 @@ var util = require('util'), colors = require('colors'), http = require('http'), - httpProxy = require('./../lib/node-http-proxy'); + httpProxy = require('../../lib/node-http-proxy'); // // Setup proxy server with forwarding @@ -60,4 +60,4 @@ http.createServer(function (req, res) { util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8003 '.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); +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/latent-proxy.js b/examples/http/latent-proxy.js index f2e51f8fb..5da559873 100644 --- a/examples/http/latent-proxy.js +++ b/examples/http/latent-proxy.js @@ -27,13 +27,13 @@ var util = require('util'), colors = require('colors'), http = require('http'), - httpProxy = require('./../lib/node-http-proxy'); + httpProxy = require('../../lib/node-http-proxy'); // // Http Proxy Server with Latency // httpProxy.createServer(function (req, res, proxy) { - var buffer = proxy.buffer(req); + var buffer = httpProxy.buffer(req); setTimeout(function() { proxy.proxyRequest(req, res, { port: 9000, diff --git a/examples/http/proxy-https-to-http.js b/examples/http/proxy-https-to-http.js index 059c31161..7018301ac 100644 --- a/examples/http/proxy-https-to-http.js +++ b/examples/http/proxy-https-to-http.js @@ -28,7 +28,7 @@ var https = require('https'), http = require('http'), util = require('util'), colors = require('colors'), - httpProxy = require('./../lib/node-http-proxy'), + httpProxy = require('../../lib/node-http-proxy'), helpers = require('./../test/helpers'); var opts = helpers.loadHttps(); diff --git a/examples/http/proxy-https-to-https.js b/examples/http/proxy-https-to-https.js index d93cab836..cde2e129d 100644 --- a/examples/http/proxy-https-to-https.js +++ b/examples/http/proxy-https-to-https.js @@ -28,7 +28,7 @@ var https = require('https'), http = require('http'), util = require('util'), colors = require('colors'), - httpProxy = require('./../lib/node-http-proxy'), + httpProxy = require('../../lib/node-http-proxy'), helpers = require('./../test/helpers'); var opts = helpers.loadHttps(); diff --git a/examples/http/proxy-table.js b/examples/http/proxy-table.js index 5036dcdfb..55d97aed5 100644 --- a/examples/http/proxy-table.js +++ b/examples/http/proxy-table.js @@ -27,7 +27,7 @@ var util = require('util'), colors = require('colors'), http = require('http'), - httpProxy = require('./../lib/node-http-proxy'); + httpProxy = require('../../lib/node-http-proxy'); // // Http Proxy Server with Proxy Table diff --git a/examples/http/standalone-proxy.js b/examples/http/standalone-proxy.js index 768d0b7a0..e39d4b072 100644 --- a/examples/http/standalone-proxy.js +++ b/examples/http/standalone-proxy.js @@ -27,14 +27,14 @@ var util = require('util'), colors = require('colors'), http = require('http'), - httpProxy = require('./../lib/node-http-proxy'); + httpProxy = require('../../lib/node-http-proxy'); // // Http Server with proxyRequest Handler and Latency // var proxy = new httpProxy.HttpProxy(); http.createServer(function (req, res) { - var buffer = proxy.buffer(req); + var buffer = httpProxy.buffer(req); setTimeout(function() { proxy.proxyRequest(req, res, { port: 9000, diff --git a/examples/middleware/gzip-middleware.js b/examples/middleware/gzip-middleware.js index 856e2f6e8..29097ecd3 100644 --- a/examples/middleware/gzip-middleware.js +++ b/examples/middleware/gzip-middleware.js @@ -27,7 +27,7 @@ var util = require('util'), colors = require('colors'), http = require('http'), - httpProxy = require('./../lib/node-http-proxy'); + httpProxy = require('../../lib/node-http-proxy'); // // Basic Http Proxy Server diff --git a/examples/middleware/jsonp-middleware.js b/examples/middleware/jsonp-middleware.js index 11cc65877..4cc31ddcb 100644 --- a/examples/middleware/jsonp-middleware.js +++ b/examples/middleware/jsonp-middleware.js @@ -27,4 +27,4 @@ http.createServer(new Store().handler()).listen(7531) require('http-proxy').createServer( require('connect-jsonp')(true), 'localhost', 7531 -).listen(1337) +).listen(1337) \ No newline at end of file diff --git a/examples/middleware/url-middleware.js b/examples/middleware/url-middleware.js index 79fdf32c6..06fd47867 100644 --- a/examples/middleware/url-middleware.js +++ b/examples/middleware/url-middleware.js @@ -37,7 +37,7 @@ httpProxy.createServer( // This is where our middlewares go, with any options desired - in this case, // the list of routes/URLs and their destinations. // - require('proxy-by-url')({ + require('proxy-by-url')({ '/hello': { port: 9000, host: 'localhost' }, '/charlie': { port: 80, host: 'charlieistheman.com' }, '/google': { port: 80, host: 'google.com' } diff --git a/examples/middleware/url-middleware2.js b/examples/middleware/url-middleware2.js index 95dfef46b..fcf3df24c 100644 --- a/examples/middleware/url-middleware2.js +++ b/examples/middleware/url-middleware2.js @@ -19,12 +19,11 @@ httpProxy.createServer( // // Target Http Server (to listen for requests on 'localhost') // -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); +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); // And finally, some colored startup output. util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow); diff --git a/examples/websocket/latent-websocket-proxy.js b/examples/websocket/latent-websocket-proxy.js index 2b9f0f06a..3598ca926 100644 --- a/examples/websocket/latent-websocket-proxy.js +++ b/examples/websocket/latent-websocket-proxy.js @@ -28,7 +28,7 @@ var sys = require('sys'), http = require('http'), colors = require('colors'), websocket = require('./../vendor/websocket'), - httpProxy = require('./../lib/node-http-proxy'); + httpProxy = require('../../lib/node-http-proxy'); try { var utils = require('socket.io/lib/socket.io/utils'), @@ -80,7 +80,7 @@ var proxyServer = http.createServer(function (req, res) { // WebSocket requests as well. // proxyServer.on('upgrade', function (req, socket, head) { - var buffer = proxy.buffer(socket); + var buffer = httpProxy.buffer(socket); setTimeout(function () { proxy.proxyWebSocketRequest(req, socket, head, { diff --git a/examples/websocket/standalone-websocket-proxy.js b/examples/websocket/standalone-websocket-proxy.js index e750c5ae3..fdefa6d28 100644 --- a/examples/websocket/standalone-websocket-proxy.js +++ b/examples/websocket/standalone-websocket-proxy.js @@ -28,7 +28,7 @@ var sys = require('sys'), http = require('http'), colors = require('colors'), websocket = require('./../vendor/websocket'), - httpProxy = require('./../lib/node-http-proxy'); + httpProxy = require('../../lib/node-http-proxy'); try { var utils = require('socket.io/lib/socket.io/utils'), diff --git a/examples/websocket/websocket-proxy.js b/examples/websocket/websocket-proxy.js index d7a8efa71..a1e49c61b 100644 --- a/examples/websocket/websocket-proxy.js +++ b/examples/websocket/websocket-proxy.js @@ -28,7 +28,7 @@ var sys = require('sys'), http = require('http'), colors = require('colors'), websocket = require('./../vendor/websocket'), - httpProxy = require('./../lib/node-http-proxy'); + httpProxy = require('../../lib/node-http-proxy'); try { var utils = require('socket.io/lib/socket.io/utils'),