Skip to content

Readme fixes #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 21, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ var http = require('http'),
//
// Create a new instance of HttProxy to use in your server
//
var proxy = new httpProxy.HttpProxy();
var proxy = new httpProxy.RoutingProxy();

//
// Create a regular http server and proxy its handler
Expand Down Expand Up @@ -247,12 +247,14 @@ httpProxy.createServer(8000, 'localhost', options).listen(8001);
//
// Create an instance of HttpProxy to use with another HTTPS server
//
var proxy = new httpProxy.HttpProxy();
https.createServer(options.https, function (req, res) {
proxy.proxyRequest(req, res, {
var proxy = new httpProxy.HttpProxy({
target: {
host: 'localhost',
port: 8000
})
}
});
https.createServer(options.https, function (req, res) {
proxy.proxyRequest(req, res)
}).listen(8002);

//
Expand All @@ -266,7 +268,7 @@ http.createServer(function (req, res) {
```

### Proxying to HTTPS from HTTPS
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`.
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`.

``` js
var fs = require('fs'),
Expand All @@ -293,15 +295,14 @@ httpProxy.createServer(8000, 'localhost', options).listen(8001);
//
var proxy = new httpProxy.HttpProxy({
target: {
host: 'localhost',
port: 8000,
https: true
}
});

https.createServer(options.https, function (req, res) {
proxy.proxyRequest(req, res, {
host: 'localhost',
port: 8000
})
proxy.proxyRequest(req, res);
}).listen(8002);

//
Expand All @@ -325,7 +326,7 @@ httpProxy.createServer(
```

## Proxying WebSockets
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:
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:

``` js
var http = require('http'),
Expand All @@ -334,26 +335,24 @@ var http = require('http'),
//
// Create an instance of node-http-proxy
//
var proxy = new httpProxy.HttpProxy();
var proxy = new httpProxy.HttpProxy(
target: {
host: 'localhost',
port: 8000
});

var server = http.createServer(function (req, res) {
//
// Proxy normal HTTP requests
//
proxy.proxyRequest(req, res, {
host: 'localhost',
port: 8000
})
proxy.proxyRequest(req, res);
});

server.on('upgrade', function(req, socket, head) {
//
// Proxy websocket requests too
//
proxy.proxyWebSocketRequest(req, socket, head, {
host: 'localhost',
port: 8000
});
proxy.proxyWebSocketRequest(req, socket, head);
});
```

Expand Down
2 changes: 1 addition & 1 deletion examples/http/standalone-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var util = require('util'),
//
// Http Server with proxyRequest Handler and Latency
//
var proxy = new httpProxy.HttpProxy();
var proxy = new httpProxy.RoutingProxy();
http.createServer(function (req, res) {
var buffer = httpProxy.buffer(req);
setTimeout(function() {
Expand Down
18 changes: 8 additions & 10 deletions examples/websocket/latent-websocket-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
var sys = require('sys'),
http = require('http'),
colors = require('colors'),
websocket = require('./../vendor/websocket'),
websocket = require('../../vendor/websocket'),
httpProxy = require('../../lib/node-http-proxy');

try {
Expand Down Expand Up @@ -67,12 +67,14 @@ socket.on('connection', function (client) {
//
// Setup our server to proxy standard HTTP requests
//
var proxy = new httpProxy.HttpProxy();
var proxyServer = http.createServer(function (req, res) {
proxy.proxyRequest(req, res, {
var proxy = new httpProxy.HttpProxy({
target: {
host: 'localhost',
port: 8080
})
}
});
var proxyServer = http.createServer(function (req, res) {
proxy.proxyRequest(req, res);
});

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

setTimeout(function () {
proxy.proxyWebSocketRequest(req, socket, head, {
port: 8080,
host: 'localhost',
buffer: buffer
});
proxy.proxyWebSocketRequest(req, socket, head, buffer);
}, 1000);
});

Expand Down
17 changes: 8 additions & 9 deletions examples/websocket/standalone-websocket-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
var sys = require('sys'),
http = require('http'),
colors = require('colors'),
websocket = require('./../vendor/websocket'),
websocket = require('../../vendor/websocket'),
httpProxy = require('../../lib/node-http-proxy');

try {
Expand Down Expand Up @@ -67,23 +67,22 @@ socket.on('connection', function (client) {
//
// Setup our server to proxy standard HTTP requests
//
var proxy = new httpProxy.HttpProxy();
var proxyServer = http.createServer(function (req, res) {
proxy.proxyRequest(req, res, {
var proxy = new httpProxy.HttpProxy({
target: {
host: 'localhost',
port: 8080
})
}
});
var proxyServer = http.createServer(function (req, res) {
proxy.proxyRequest(req, res);
});

//
// Listen to the `upgrade` event and proxy the
// WebSocket requests as well.
//
proxyServer.on('upgrade', function (req, socket, head) {
proxy.proxyWebSocketRequest(req, socket, head, {
port: 8080,
host: 'localhost'
});
proxy.proxyWebSocketRequest(req, socket, head);
});

proxyServer.listen(8081);
Expand Down
2 changes: 1 addition & 1 deletion examples/websocket/websocket-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
var sys = require('sys'),
http = require('http'),
colors = require('colors'),
websocket = require('./../vendor/websocket'),
websocket = require('../../vendor/websocket'),
httpProxy = require('../../lib/node-http-proxy');

try {
Expand Down