From 45d2adea2cccfdb07f89dd3cdafe538e711c2a00 Mon Sep 17 00:00:00 2001 From: Pierre Mage Date: Sat, 6 Jun 2020 01:17:21 +0100 Subject: [PATCH 1/2] [examples] util.debug and util.puts have been removed in Node.js v12.x * Replace util.debug with console.debug * Replace util.puts with console.log --- examples/http/basic-proxy.js | 9 ++++----- examples/http/concurrent-proxy.js | 7 +++---- examples/http/custom-proxy-error.js | 5 ++--- examples/http/error-handling.js | 5 ++--- examples/http/forward-and-target-proxy.js | 11 +++++------ examples/http/forward-proxy.js | 9 ++++----- examples/http/latent-proxy.js | 7 +++---- examples/http/proxy-http-to-https.js | 3 +-- examples/http/proxy-https-to-http.js | 5 ++--- examples/http/proxy-https-to-https.js | 5 ++--- examples/http/reverse-proxy.js | 7 +++---- examples/http/sse.js | 7 +++---- examples/http/standalone-proxy.js | 7 +++---- examples/middleware/bodyDecoder-middleware.js | 1 - examples/middleware/gzip-middleware.js | 7 +++---- examples/middleware/modifyResponse-middleware.js | 7 +++---- examples/websocket/latent-websocket-proxy.js | 9 ++++----- examples/websocket/standalone-websocket-proxy.js | 9 ++++----- examples/websocket/websocket-proxy.js | 9 ++++----- 19 files changed, 55 insertions(+), 74 deletions(-) diff --git a/examples/http/basic-proxy.js b/examples/http/basic-proxy.js index dede897f3..7164ae7a6 100644 --- a/examples/http/basic-proxy.js +++ b/examples/http/basic-proxy.js @@ -24,8 +24,7 @@ */ -var util = require('util'), - colors = require('colors'), +var colors = require('colors'), http = require('http'), httpProxy = require('../../lib/http-proxy'); @@ -38,7 +37,7 @@ var welcome = [ '# # # # # # # # #### # # # ' ].join('\n'); -util.puts(welcome.rainbow.bold); +console.log(welcome.rainbow.bold); // // Basic Http Proxy Server @@ -56,5 +55,5 @@ http.createServer(function (req, res) { res.end(); }).listen(9003); -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); +console.log('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8003'.yellow); +console.log('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 7e54935dd..2c030571f 100644 --- a/examples/http/concurrent-proxy.js +++ b/examples/http/concurrent-proxy.js @@ -24,8 +24,7 @@ */ -var util = require('util'), - colors = require('colors'), +var colors = require('colors'), http = require('http'), httpProxy = require('../../lib/http-proxy'); @@ -64,5 +63,5 @@ http.createServer(function (req, res) { } }).listen(9004); -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); +console.log('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8004'.yellow); +console.log('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 855995fdf..1b7b5b4ae 100644 --- a/examples/http/custom-proxy-error.js +++ b/examples/http/custom-proxy-error.js @@ -24,8 +24,7 @@ */ -var util = require('util'), - colors = require('colors'), +var colors = require('colors'), http = require('http'), httpProxy = require('../../lib/http-proxy'); @@ -52,4 +51,4 @@ proxy.on('error', function (err, req, res) { }); -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 +console.log('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/error-handling.js b/examples/http/error-handling.js index a20360325..f05148190 100644 --- a/examples/http/error-handling.js +++ b/examples/http/error-handling.js @@ -24,8 +24,7 @@ */ -var util = require('util'), - colors = require('colors'), +var colors = require('colors'), http = require('http'), httpProxy = require('../../lib/http-proxy'); @@ -60,4 +59,4 @@ function requestHandler(req, res) { } http.createServer(requestHandler).listen(8000); -util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow); +console.log('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow); diff --git a/examples/http/forward-and-target-proxy.js b/examples/http/forward-and-target-proxy.js index 5f4231add..19121144d 100644 --- a/examples/http/forward-and-target-proxy.js +++ b/examples/http/forward-and-target-proxy.js @@ -24,8 +24,7 @@ */ -var util = require('util'), - colors = require('colors'), +var colors = require('colors'), http = require('http'), httpProxy = require('../../lib/http-proxy'); @@ -56,12 +55,12 @@ http.createServer(function (req, res) { // Target Http Forwarding Server // http.createServer(function (req, res) { - util.puts('Receiving forward for: ' + req.url); + 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(9007); -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 +console.log('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8006 '.yellow + 'with forward proxy'.magenta.underline); +console.log('http server '.blue + 'started '.green.bold + 'on port '.blue + '9006 '.yellow); +console.log('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 d0bc30ca0..61a483b47 100644 --- a/examples/http/forward-proxy.js +++ b/examples/http/forward-proxy.js @@ -24,8 +24,7 @@ */ -var util = require('util'), - colors = require('colors'), +var colors = require('colors'), http = require('http'), httpProxy = require('../../lib/http-proxy'); @@ -43,11 +42,11 @@ httpProxy.createServer({ // Target Http Forwarding Server // http.createServer(function (req, res) { - util.puts('Receiving forward for: ' + req.url); + 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(9019); -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 +console.log('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8019 '.yellow + 'with forward proxy'.magenta.underline); +console.log('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 0c8ba5d16..d69f32656 100644 --- a/examples/http/latent-proxy.js +++ b/examples/http/latent-proxy.js @@ -24,8 +24,7 @@ */ -var util = require('util'), - colors = require('colors'), +var colors = require('colors'), http = require('http'), httpProxy = require('../../lib/http-proxy'); @@ -50,5 +49,5 @@ http.createServer(function (req, res) { res.end(); }).listen(9008); -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); +console.log('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8008 '.yellow + 'with latency'.magenta.underline); +console.log('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 4df98e4d6..45fa9e87c 100644 --- a/examples/http/proxy-http-to-https.js +++ b/examples/http/proxy-http-to-https.js @@ -26,7 +26,6 @@ var https = require('https'), http = require('http'), - util = require('util'), path = require('path'), fs = require('fs'), colors = require('colors'), @@ -43,4 +42,4 @@ httpProxy.createProxyServer({ } }).listen(8011); -util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8011'.yellow); \ No newline at end of file +console.log('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 5eb07a14c..769d42f62 100644 --- a/examples/http/proxy-https-to-http.js +++ b/examples/http/proxy-https-to-http.js @@ -26,7 +26,6 @@ var https = require('https'), http = require('http'), - util = require('util'), path = require('path'), fs = require('fs'), colors = require('colors'), @@ -56,5 +55,5 @@ httpProxy.createServer({ } }).listen(8009); -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); +console.log('https proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8009'.yellow); +console.log('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 e600f389c..d92b7349d 100644 --- a/examples/http/proxy-https-to-https.js +++ b/examples/http/proxy-https-to-https.js @@ -26,7 +26,6 @@ var https = require('https'), http = require('http'), - util = require('util'), fs = require('fs'), path = require('path'), colors = require('colors'), @@ -55,5 +54,5 @@ httpProxy.createServer({ secure: false }).listen(8010); -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); +console.log('https proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8010'.yellow); +console.log('https server '.blue + 'started '.green.bold + 'on port '.blue + '9010 '.yellow); diff --git a/examples/http/reverse-proxy.js b/examples/http/reverse-proxy.js index b07caa5a8..f85ec2d51 100644 --- a/examples/http/reverse-proxy.js +++ b/examples/http/reverse-proxy.js @@ -24,20 +24,19 @@ var http = require('http'), net = require('net'), httpProxy = require('../../lib/http-proxy'), - url = require('url'), - util = require('util'); + url = require('url'); var proxy = httpProxy.createServer(); var server = http.createServer(function (req, res) { - util.puts('Receiving reverse proxy request for:' + req.url); + console.log('Receiving reverse proxy request for:' + req.url); var parsedUrl = url.parse(req.url); var target = parsedUrl.protocol + '//' + parsedUrl.hostname; proxy.web(req, res, {target: target, secure: false}); }).listen(8213); server.on('connect', function (req, socket) { - util.puts('Receiving reverse proxy request for:' + req.url); + console.log('Receiving reverse proxy request for:' + req.url); var serverUrl = url.parse('https://' + req.url); diff --git a/examples/http/sse.js b/examples/http/sse.js index ef4693ec3..34bc5df08 100644 --- a/examples/http/sse.js +++ b/examples/http/sse.js @@ -24,8 +24,7 @@ */ -var util = require('util'), - colors = require('colors'), +var colors = require('colors'), http = require('http'), httpProxy = require('../../lib/http-proxy'), SSE = require('sse'); @@ -63,5 +62,5 @@ sse.on('connection', function(client) { server.listen(9003); -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); +console.log('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8003'.yellow); +console.log('http server '.blue + 'started '.green.bold + 'on port '.blue + '9003 '.yellow); diff --git a/examples/http/standalone-proxy.js b/examples/http/standalone-proxy.js index 0c89c6cdb..cc9e33870 100644 --- a/examples/http/standalone-proxy.js +++ b/examples/http/standalone-proxy.js @@ -24,8 +24,7 @@ */ -var util = require('util'), - colors = require('colors'), +var colors = require('colors'), http = require('http'), httpProxy = require('../../lib/http-proxy'); @@ -50,5 +49,5 @@ http.createServer(function (req, res) { res.end(); }).listen(9002); -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 + '9002 '.yellow); +console.log('http server '.blue + 'started '.green.bold + 'on port '.blue + '8002 '.yellow + 'with proxy.web() handler'.cyan.underline + ' and latency'.magenta); +console.log('http server '.blue + 'started '.green.bold + 'on port '.blue + '9002 '.yellow); diff --git a/examples/middleware/bodyDecoder-middleware.js b/examples/middleware/bodyDecoder-middleware.js index 71e16c8ac..030f454fb 100644 --- a/examples/middleware/bodyDecoder-middleware.js +++ b/examples/middleware/bodyDecoder-middleware.js @@ -28,7 +28,6 @@ var http = require('http'), connect = require('connect'), request = require('request'), colors = require('colors'), - util = require('util'), queryString = require('querystring'), bodyParser = require('body-parser'), httpProxy = require('../../lib/http-proxy'), diff --git a/examples/middleware/gzip-middleware.js b/examples/middleware/gzip-middleware.js index 7cbb49a0c..7220656cb 100644 --- a/examples/middleware/gzip-middleware.js +++ b/examples/middleware/gzip-middleware.js @@ -24,8 +24,7 @@ */ -var util = require('util'), - colors = require('colors'), +var colors = require('colors'), http = require('http'), connect = require('connect'), httpProxy = require('../../lib/http-proxy'); @@ -61,5 +60,5 @@ http.createServer(function (req, res) { res.end(); }).listen(9012); -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); +console.log('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8012'.yellow); +console.log('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 41c4cec8c..333eb3a33 100644 --- a/examples/middleware/modifyResponse-middleware.js +++ b/examples/middleware/modifyResponse-middleware.js @@ -24,8 +24,7 @@ */ -var util = require('util'), - colors = require('colors'), +var colors = require('colors'), http = require('http'), connect = require('connect'), app = connect(), @@ -64,6 +63,6 @@ http.createServer(function (req, res) { res.end('Hello, I love Ruby\n'); }).listen(9013); -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); +console.log('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8013'.yellow); +console.log('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 f5ad868bc..013e6822a 100644 --- a/examples/websocket/latent-websocket-proxy.js +++ b/examples/websocket/latent-websocket-proxy.js @@ -24,8 +24,7 @@ */ -var util = require('util'), - http = require('http'), +var http = require('http'), colors = require('colors'), httpProxy = require('../../lib/http-proxy'); @@ -45,10 +44,10 @@ catch (ex) { // var server = io.listen(9016); server.sockets.on('connection', function (client) { - util.debug('Got websocket connection'); + console.debug('Got websocket connection'); client.on('message', function (msg) { - util.debug('Got message from client: ' + msg); + console.debug('Got message from client: ' + msg); }); client.send('from server'); @@ -86,6 +85,6 @@ proxyServer.listen(8016); var ws = client.connect('ws://localhost:8016'); ws.on('message', function (msg) { - util.debug('Got message: ' + msg); + console.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 index 78ac697f0..3c56577c6 100644 --- a/examples/websocket/standalone-websocket-proxy.js +++ b/examples/websocket/standalone-websocket-proxy.js @@ -24,8 +24,7 @@ */ -var util = require('util'), - http = require('http'), +var http = require('http'), colors = require('colors'), httpProxy = require('../../lib/http-proxy'); @@ -45,10 +44,10 @@ catch (ex) { // var server = io.listen(9015); server.sockets.on('connection', function (client) { - util.debug('Got websocket connection'); + console.debug('Got websocket connection'); client.on('message', function (msg) { - util.debug('Got message from client: ' + msg); + console.debug('Got message from client: ' + msg); }); client.send('from server'); @@ -83,6 +82,6 @@ proxyServer.listen(8015); var ws = client.connect('ws://localhost:8015'); ws.on('message', function (msg) { - util.debug('Got message: ' + msg); + console.debug('Got message: ' + msg); ws.send('I am the client'); }); diff --git a/examples/websocket/websocket-proxy.js b/examples/websocket/websocket-proxy.js index 5feacb4f4..bb42b4d79 100644 --- a/examples/websocket/websocket-proxy.js +++ b/examples/websocket/websocket-proxy.js @@ -24,8 +24,7 @@ */ -var util = require('util'), - http = require('http'), +var http = require('http'), colors = require('colors'), httpProxy = require('../../lib/http-proxy'); @@ -45,10 +44,10 @@ catch (ex) { // var server = io.listen(9014); server.sockets.on('connection', function (client) { - util.debug('Got websocket connection'); + console.debug('Got websocket connection'); client.on('message', function (msg) { - util.debug('Got message from client: ' + msg); + console.debug('Got message from client: ' + msg); }); client.send('from server'); @@ -65,6 +64,6 @@ httpProxy.createServer({ target: 'ws://localhost:9014', ws: true }).listen(8014) var ws = client.connect('ws://localhost:8014'); ws.on('message', function (msg) { - util.debug('Got message: ' + msg); + console.debug('Got message: ' + msg); ws.send('I am the client'); }); From 8870ce10125eda69cee40ca0bf768b48c314fe0d Mon Sep 17 00:00:00 2001 From: Pierre Mage Date: Sat, 6 Jun 2020 01:31:50 +0100 Subject: [PATCH 2/2] [examples] Fix middleware examples --- examples/middleware/gzip-middleware.js | 19 ++++++++++--------- examples/package.json | 3 +++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/examples/middleware/gzip-middleware.js b/examples/middleware/gzip-middleware.js index 7220656cb..1567aff4a 100644 --- a/examples/middleware/gzip-middleware.js +++ b/examples/middleware/gzip-middleware.js @@ -27,22 +27,23 @@ var colors = require('colors'), http = require('http'), connect = require('connect'), + compression = require('compression'), httpProxy = require('../../lib/http-proxy'); // // Basic Connect App // -connect.createServer( - connect.compress({ - // Pass to connect.compress() the options +connect() + .use(compression({ + // Pass to compression() the options // that you need, just for show the example - // we use threshold to 1 - threshold: 1 - }), - function (req, res) { + // we use level to 1 + level: 1 + })) + .use(function (req, res) { proxy.web(req, res); - } -).listen(8012); + }) + .listen(8012); // // Basic Http Proxy Server diff --git a/examples/package.json b/examples/package.json index 6a3812fa1..44b6f9825 100644 --- a/examples/package.json +++ b/examples/package.json @@ -4,7 +4,10 @@ "version": "0.0.0", "dependencies": { "agentkeepalive": "^4.0.0", + "body-parser": "^1.19.0", "colors": "~1.3.0", + "compression": "^1.7.4", + "connect": "^3.7.0", "connect-restreamer": "~1.0.0", "request": "~2.88.0", "socket.io": "~0.9.16",