Skip to content

Commit 24ef919

Browse files
committed
[docs] Updated examples in README.md for 0.7.x API.
1 parent 787370e commit 24ef919

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
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

0 commit comments

Comments
 (0)