Skip to content

Commit 2b2c4ab

Browse files
committed
Merge pull request #114 from nodejitsu/readme-fixes
Readme fixes
2 parents e5693d2 + 549360a commit 2b2c4ab

File tree

5 files changed

+37
-41
lines changed

5 files changed

+37
-41
lines changed

README.md

+19-20
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ var http = require('http'),
145145
//
146146
// Create a new instance of HttProxy to use in your server
147147
//
148-
var proxy = new httpProxy.HttpProxy();
148+
var proxy = new httpProxy.RoutingProxy();
149149

150150
//
151151
// Create a regular http server and proxy its handler
@@ -247,12 +247,14 @@ httpProxy.createServer(8000, 'localhost', options).listen(8001);
247247
//
248248
// Create an instance of HttpProxy to use with another HTTPS server
249249
//
250-
var proxy = new httpProxy.HttpProxy();
251-
https.createServer(options.https, function (req, res) {
252-
proxy.proxyRequest(req, res, {
250+
var proxy = new httpProxy.HttpProxy({
251+
target: {
253252
host: 'localhost',
254253
port: 8000
255-
})
254+
}
255+
});
256+
https.createServer(options.https, function (req, res) {
257+
proxy.proxyRequest(req, res)
256258
}).listen(8002);
257259

258260
//
@@ -266,7 +268,7 @@ http.createServer(function (req, res) {
266268
```
267269

268270
### Proxying to HTTPS from HTTPS
269-
Proxying from HTTPS to HTTPS is essentially the same as proxying from HTTPS to HTTP, but you must include `target` option in when calling `httpProxy.createServer` or instantiating a new instance of `HttpProxy`.
271+
Proxying from HTTPS to HTTPS is essentially the same as proxying from HTTPS to HTTP, but you must include the `target` option in when calling `httpProxy.createServer` or instantiating a new instance of `HttpProxy`.
270272

271273
``` js
272274
var fs = require('fs'),
@@ -293,15 +295,14 @@ httpProxy.createServer(8000, 'localhost', options).listen(8001);
293295
//
294296
var proxy = new httpProxy.HttpProxy({
295297
target: {
298+
host: 'localhost',
299+
port: 8000,
296300
https: true
297301
}
298302
});
299303

300304
https.createServer(options.https, function (req, res) {
301-
proxy.proxyRequest(req, res, {
302-
host: 'localhost',
303-
port: 8000
304-
})
305+
proxy.proxyRequest(req, res);
305306
}).listen(8002);
306307

307308
//
@@ -325,7 +326,7 @@ httpProxy.createServer(
325326
```
326327

327328
## Proxying WebSockets
328-
Websockets are handled automatically when using the `httpProxy.createServer()`, but if you want to use it in conjunction with a stand-alone HTTP + WebSocket (such as [socket.io][5]) server here's how:
329+
Websockets are handled automatically when using `httpProxy.createServer()`, but if you want to use it in conjunction with a stand-alone HTTP + WebSocket (such as [socket.io][5]) server here's how:
329330

330331
``` js
331332
var http = require('http'),
@@ -334,26 +335,24 @@ var http = require('http'),
334335
//
335336
// Create an instance of node-http-proxy
336337
//
337-
var proxy = new httpProxy.HttpProxy();
338+
var proxy = new httpProxy.HttpProxy(
339+
target: {
340+
host: 'localhost',
341+
port: 8000
342+
});
338343

339344
var server = http.createServer(function (req, res) {
340345
//
341346
// Proxy normal HTTP requests
342347
//
343-
proxy.proxyRequest(req, res, {
344-
host: 'localhost',
345-
port: 8000
346-
})
348+
proxy.proxyRequest(req, res);
347349
});
348350

349351
server.on('upgrade', function(req, socket, head) {
350352
//
351353
// Proxy websocket requests too
352354
//
353-
proxy.proxyWebSocketRequest(req, socket, head, {
354-
host: 'localhost',
355-
port: 8000
356-
});
355+
proxy.proxyWebSocketRequest(req, socket, head);
357356
});
358357
```
359358

examples/http/standalone-proxy.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var util = require('util'),
3232
//
3333
// Http Server with proxyRequest Handler and Latency
3434
//
35-
var proxy = new httpProxy.HttpProxy();
35+
var proxy = new httpProxy.RoutingProxy();
3636
http.createServer(function (req, res) {
3737
var buffer = httpProxy.buffer(req);
3838
setTimeout(function() {

examples/websocket/latent-websocket-proxy.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
var sys = require('sys'),
2828
http = require('http'),
2929
colors = require('colors'),
30-
websocket = require('./../vendor/websocket'),
30+
websocket = require('../../vendor/websocket'),
3131
httpProxy = require('../../lib/node-http-proxy');
3232

3333
try {
@@ -67,12 +67,14 @@ socket.on('connection', function (client) {
6767
//
6868
// Setup our server to proxy standard HTTP requests
6969
//
70-
var proxy = new httpProxy.HttpProxy();
71-
var proxyServer = http.createServer(function (req, res) {
72-
proxy.proxyRequest(req, res, {
70+
var proxy = new httpProxy.HttpProxy({
71+
target: {
7372
host: 'localhost',
7473
port: 8080
75-
})
74+
}
75+
});
76+
var proxyServer = http.createServer(function (req, res) {
77+
proxy.proxyRequest(req, res);
7678
});
7779

7880
//
@@ -83,11 +85,7 @@ proxyServer.on('upgrade', function (req, socket, head) {
8385
var buffer = httpProxy.buffer(socket);
8486

8587
setTimeout(function () {
86-
proxy.proxyWebSocketRequest(req, socket, head, {
87-
port: 8080,
88-
host: 'localhost',
89-
buffer: buffer
90-
});
88+
proxy.proxyWebSocketRequest(req, socket, head, buffer);
9189
}, 1000);
9290
});
9391

examples/websocket/standalone-websocket-proxy.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
var sys = require('sys'),
2828
http = require('http'),
2929
colors = require('colors'),
30-
websocket = require('./../vendor/websocket'),
30+
websocket = require('../../vendor/websocket'),
3131
httpProxy = require('../../lib/node-http-proxy');
3232

3333
try {
@@ -67,23 +67,22 @@ socket.on('connection', function (client) {
6767
//
6868
// Setup our server to proxy standard HTTP requests
6969
//
70-
var proxy = new httpProxy.HttpProxy();
71-
var proxyServer = http.createServer(function (req, res) {
72-
proxy.proxyRequest(req, res, {
70+
var proxy = new httpProxy.HttpProxy({
71+
target: {
7372
host: 'localhost',
7473
port: 8080
75-
})
74+
}
75+
});
76+
var proxyServer = http.createServer(function (req, res) {
77+
proxy.proxyRequest(req, res);
7678
});
7779

7880
//
7981
// Listen to the `upgrade` event and proxy the
8082
// WebSocket requests as well.
8183
//
8284
proxyServer.on('upgrade', function (req, socket, head) {
83-
proxy.proxyWebSocketRequest(req, socket, head, {
84-
port: 8080,
85-
host: 'localhost'
86-
});
85+
proxy.proxyWebSocketRequest(req, socket, head);
8786
});
8887

8988
proxyServer.listen(8081);

examples/websocket/websocket-proxy.js

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

3333
try {

0 commit comments

Comments
 (0)