Skip to content

Commit 13eaec5

Browse files
committed
[doc] Updated examples
1 parent 2cd8256 commit 13eaec5

17 files changed

+49
-56
lines changed

Diff for: examples/helpers/store.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11

2-
module.exports = Store
32
//
43
// just to make these example a little bit interesting,
54
// make a little key value store with an http interface
@@ -20,12 +19,10 @@ module.exports = Store
2019
//
2120
// TODO: cached map-reduce views and auto-magic sharding.
2221
//
22+
var Store = module.exports = function Store () {
23+
this.store = {};
24+
};
2325

24-
25-
26-
function Store () {
27-
this.store = {}
28-
}
2926
Store.prototype = {
3027
get: function (key) {
3128
return this.store[key]

Diff for: examples/http/basic-proxy.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,17 @@
2727
var util = require('util'),
2828
colors = require('colors'),
2929
http = require('http'),
30-
httpProxy = require('./../lib/node-http-proxy');
31-
32-
// ascii art from http://github.com/marak/asciimo
33-
var welcome = '\
34-
# # ##### ##### ##### ##### ##### #### # # # # \n\
35-
# # # # # # # # # # # # # # # # \n\
36-
###### # # # # ##### # # # # # # ## # \n\
37-
# # # # ##### ##### ##### # # ## # \n\
38-
# # # # # # # # # # # # # \n\
39-
# # # # # # # # #### # # # \n';
30+
httpProxy = require('../../lib/node-http-proxy');
31+
32+
var welcome = [
33+
'# # ##### ##### ##### ##### ##### #### # # # #',
34+
'# # # # # # # # # # # # # # # # ',
35+
'###### # # # # ##### # # # # # # ## # ',
36+
'# # # # ##### ##### ##### # # ## # ',
37+
'# # # # # # # # # # # # # ',
38+
'# # # # # # # # #### # # # '
39+
].join('\n');
40+
4041
util.puts(welcome.rainbow.bold);
4142

4243
//

Diff for: examples/http/concurrent-proxy.js

+12-11
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
var util = require('util'),
2828
colors = require('colors'),
2929
http = require('http'),
30-
httpProxy = require('./../lib/node-http-proxy');
30+
httpProxy = require('../../lib/node-http-proxy');
3131

3232
//
3333
// Basic Http Proxy Server
@@ -42,23 +42,24 @@ httpProxy.createServer(9000, 'localhost').listen(8000);
4242
//
4343

4444

45-
var connections = []
46-
, go
45+
var connections = [],
46+
go;
4747

4848
http.createServer(function (req, res) {
49-
50-
connections.push (function (){
49+
connections.push(function () {
5150
res.writeHead(200, { 'Content-Type': 'text/plain' });
5251
res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2));
5352
res.end();
54-
})
55-
process.stdout.write(connections.length + ', ')
53+
});
54+
55+
process.stdout.write(connections.length + ', ');
56+
5657
if (connections.length > 110 || go) {
57-
go = true
58-
while(connections.length)
59-
connections.shift()()
58+
go = true;
59+
while (connections.length) {
60+
connections.shift()();
61+
}
6062
}
61-
6263
}).listen(9000);
6364

6465
util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow);

Diff for: examples/http/custom-proxy-error.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,12 @@
2727
var util = require('util'),
2828
colors = require('colors'),
2929
http = require('http'),
30-
httpProxy = require('./../lib/node-http-proxy');
30+
httpProxy = require('../../lib/node-http-proxy');
3131

3232
//
3333
// Http Proxy Server with Latency
3434
//
35-
var server = httpProxy.createServer(function (req, res, proxy) {
36-
proxy.proxyRequest(req, res, {
37-
port: 9000,
38-
host: 'localhost'
39-
});
40-
})
35+
var server = httpProxy.createServer(9000, 'localhost');
4136

4237
//
4338
// Tell the server to listen on port 8002

Diff for: examples/http/forward-proxy.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
var util = require('util'),
2828
colors = require('colors'),
2929
http = require('http'),
30-
httpProxy = require('./../lib/node-http-proxy');
30+
httpProxy = require('../../lib/node-http-proxy');
3131

3232
//
3333
// Setup proxy server with forwarding
@@ -60,4 +60,4 @@ http.createServer(function (req, res) {
6060

6161
util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8003 '.yellow + 'with forward proxy'.magenta.underline);
6262
util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow);
63-
util.puts('http forward server '.blue + 'started '.green.bold + 'on port '.blue + '9001 '.yellow);
63+
util.puts('http forward server '.blue + 'started '.green.bold + 'on port '.blue + '9001 '.yellow);

Diff for: examples/http/latent-proxy.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
var util = require('util'),
2828
colors = require('colors'),
2929
http = require('http'),
30-
httpProxy = require('./../lib/node-http-proxy');
30+
httpProxy = require('../../lib/node-http-proxy');
3131

3232
//
3333
// Http Proxy Server with Latency
3434
//
3535
httpProxy.createServer(function (req, res, proxy) {
36-
var buffer = proxy.buffer(req);
36+
var buffer = httpProxy.buffer(req);
3737
setTimeout(function() {
3838
proxy.proxyRequest(req, res, {
3939
port: 9000,

Diff for: examples/http/proxy-https-to-http.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var https = require('https'),
2828
http = require('http'),
2929
util = require('util'),
3030
colors = require('colors'),
31-
httpProxy = require('./../lib/node-http-proxy'),
31+
httpProxy = require('../../lib/node-http-proxy'),
3232
helpers = require('./../test/helpers');
3333

3434
var opts = helpers.loadHttps();

Diff for: examples/http/proxy-https-to-https.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var https = require('https'),
2828
http = require('http'),
2929
util = require('util'),
3030
colors = require('colors'),
31-
httpProxy = require('./../lib/node-http-proxy'),
31+
httpProxy = require('../../lib/node-http-proxy'),
3232
helpers = require('./../test/helpers');
3333

3434
var opts = helpers.loadHttps();

Diff for: examples/http/proxy-table.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
var util = require('util'),
2828
colors = require('colors'),
2929
http = require('http'),
30-
httpProxy = require('./../lib/node-http-proxy');
30+
httpProxy = require('../../lib/node-http-proxy');
3131

3232
//
3333
// Http Proxy Server with Proxy Table

Diff for: examples/http/standalone-proxy.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727
var util = require('util'),
2828
colors = require('colors'),
2929
http = require('http'),
30-
httpProxy = require('./../lib/node-http-proxy');
30+
httpProxy = require('../../lib/node-http-proxy');
3131

3232
//
3333
// Http Server with proxyRequest Handler and Latency
3434
//
3535
var proxy = new httpProxy.HttpProxy();
3636
http.createServer(function (req, res) {
37-
var buffer = proxy.buffer(req);
37+
var buffer = httpProxy.buffer(req);
3838
setTimeout(function() {
3939
proxy.proxyRequest(req, res, {
4040
port: 9000,

Diff for: examples/middleware/gzip-middleware.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
var util = require('util'),
2828
colors = require('colors'),
2929
http = require('http'),
30-
httpProxy = require('./../lib/node-http-proxy');
30+
httpProxy = require('../../lib/node-http-proxy');
3131

3232
//
3333
// Basic Http Proxy Server

Diff for: examples/middleware/jsonp-middleware.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ http.createServer(new Store().handler()).listen(7531)
2727
require('http-proxy').createServer(
2828
require('connect-jsonp')(true),
2929
'localhost', 7531
30-
).listen(1337)
30+
).listen(1337)

Diff for: examples/middleware/url-middleware.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ httpProxy.createServer(
3737
// This is where our middlewares go, with any options desired - in this case,
3838
// the list of routes/URLs and their destinations.
3939
//
40-
require('proxy-by-url')({
40+
require('proxy-by-url')({
4141
'/hello': { port: 9000, host: 'localhost' },
4242
'/charlie': { port: 80, host: 'charlieistheman.com' },
4343
'/google': { port: 80, host: 'google.com' }

Diff for: examples/middleware/url-middleware2.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ httpProxy.createServer(
1919
//
2020
// Target Http Server (to listen for requests on 'localhost')
2121
//
22-
http.createServer(
23-
function (req, res) {
24-
res.writeHead(200, { 'Content-Type': 'text/plain' });
25-
res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2));
26-
res.end();
27-
}).listen(9000);
22+
http.createServer(function (req, res) {
23+
res.writeHead(200, { 'Content-Type': 'text/plain' });
24+
res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2));
25+
res.end();
26+
}).listen(9000);
2827

2928
// And finally, some colored startup output.
3029
util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow);

Diff for: examples/websocket/latent-websocket-proxy.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var sys = require('sys'),
2828
http = require('http'),
2929
colors = require('colors'),
3030
websocket = require('./../vendor/websocket'),
31-
httpProxy = require('./../lib/node-http-proxy');
31+
httpProxy = require('../../lib/node-http-proxy');
3232

3333
try {
3434
var utils = require('socket.io/lib/socket.io/utils'),
@@ -80,7 +80,7 @@ var proxyServer = http.createServer(function (req, res) {
8080
// WebSocket requests as well.
8181
//
8282
proxyServer.on('upgrade', function (req, socket, head) {
83-
var buffer = proxy.buffer(socket);
83+
var buffer = httpProxy.buffer(socket);
8484

8585
setTimeout(function () {
8686
proxy.proxyWebSocketRequest(req, socket, head, {

Diff for: examples/websocket/standalone-websocket-proxy.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var sys = require('sys'),
2828
http = require('http'),
2929
colors = require('colors'),
3030
websocket = require('./../vendor/websocket'),
31-
httpProxy = require('./../lib/node-http-proxy');
31+
httpProxy = require('../../lib/node-http-proxy');
3232

3333
try {
3434
var utils = require('socket.io/lib/socket.io/utils'),

Diff for: examples/websocket/websocket-proxy.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var sys = require('sys'),
2828
http = require('http'),
2929
colors = require('colors'),
3030
websocket = require('./../vendor/websocket'),
31-
httpProxy = require('./../lib/node-http-proxy');
31+
httpProxy = require('../../lib/node-http-proxy');
3232

3333
try {
3434
var utils = require('socket.io/lib/socket.io/utils'),

0 commit comments

Comments
 (0)