Commit 2b2c4abb authored by Charlie McConnell's avatar Charlie McConnell

Merge pull request #114 from nodejitsu/readme-fixes

Readme fixes
parents e5693d2b 549360a4
...@@ -145,7 +145,7 @@ var http = require('http'), ...@@ -145,7 +145,7 @@ var http = require('http'),
// //
// Create a new instance of HttProxy to use in your server // 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 // Create a regular http server and proxy its handler
...@@ -247,12 +247,14 @@ httpProxy.createServer(8000, 'localhost', options).listen(8001); ...@@ -247,12 +247,14 @@ httpProxy.createServer(8000, 'localhost', options).listen(8001);
// //
// Create an instance of HttpProxy to use with another HTTPS server // Create an instance of HttpProxy to use with another HTTPS server
// //
var proxy = new httpProxy.HttpProxy(); var proxy = new httpProxy.HttpProxy({
https.createServer(options.https, function (req, res) { target: {
proxy.proxyRequest(req, res, {
host: 'localhost', host: 'localhost',
port: 8000 port: 8000
}) }
});
https.createServer(options.https, function (req, res) {
proxy.proxyRequest(req, res)
}).listen(8002); }).listen(8002);
// //
...@@ -266,7 +268,7 @@ http.createServer(function (req, res) { ...@@ -266,7 +268,7 @@ http.createServer(function (req, res) {
``` ```
### Proxying to HTTPS from HTTPS ### 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 ``` js
var fs = require('fs'), var fs = require('fs'),
...@@ -293,15 +295,14 @@ httpProxy.createServer(8000, 'localhost', options).listen(8001); ...@@ -293,15 +295,14 @@ httpProxy.createServer(8000, 'localhost', options).listen(8001);
// //
var proxy = new httpProxy.HttpProxy({ var proxy = new httpProxy.HttpProxy({
target: { target: {
host: 'localhost',
port: 8000,
https: true https: true
} }
}); });
https.createServer(options.https, function (req, res) { https.createServer(options.https, function (req, res) {
proxy.proxyRequest(req, res, { proxy.proxyRequest(req, res);
host: 'localhost',
port: 8000
})
}).listen(8002); }).listen(8002);
// //
...@@ -325,7 +326,7 @@ httpProxy.createServer( ...@@ -325,7 +326,7 @@ httpProxy.createServer(
``` ```
## Proxying WebSockets ## 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 ``` js
var http = require('http'), var http = require('http'),
...@@ -334,26 +335,24 @@ var http = require('http'), ...@@ -334,26 +335,24 @@ var http = require('http'),
// //
// Create an instance of node-http-proxy // 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) { var server = http.createServer(function (req, res) {
// //
// Proxy normal HTTP requests // Proxy normal HTTP requests
// //
proxy.proxyRequest(req, res, { proxy.proxyRequest(req, res);
host: 'localhost',
port: 8000
})
}); });
server.on('upgrade', function(req, socket, head) { server.on('upgrade', function(req, socket, head) {
// //
// Proxy websocket requests too // Proxy websocket requests too
// //
proxy.proxyWebSocketRequest(req, socket, head, { proxy.proxyWebSocketRequest(req, socket, head);
host: 'localhost',
port: 8000
});
}); });
``` ```
......
...@@ -32,7 +32,7 @@ var util = require('util'), ...@@ -32,7 +32,7 @@ var util = require('util'),
// //
// Http Server with proxyRequest Handler and Latency // Http Server with proxyRequest Handler and Latency
// //
var proxy = new httpProxy.HttpProxy(); var proxy = new httpProxy.RoutingProxy();
http.createServer(function (req, res) { http.createServer(function (req, res) {
var buffer = httpProxy.buffer(req); var buffer = httpProxy.buffer(req);
setTimeout(function() { setTimeout(function() {
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
var sys = require('sys'), var sys = require('sys'),
http = require('http'), http = require('http'),
colors = require('colors'), colors = require('colors'),
websocket = require('./../vendor/websocket'), websocket = require('../../vendor/websocket'),
httpProxy = require('../../lib/node-http-proxy'); httpProxy = require('../../lib/node-http-proxy');
try { try {
...@@ -67,12 +67,14 @@ socket.on('connection', function (client) { ...@@ -67,12 +67,14 @@ socket.on('connection', function (client) {
// //
// Setup our server to proxy standard HTTP requests // Setup our server to proxy standard HTTP requests
// //
var proxy = new httpProxy.HttpProxy(); var proxy = new httpProxy.HttpProxy({
var proxyServer = http.createServer(function (req, res) { target: {
proxy.proxyRequest(req, res, {
host: 'localhost', host: 'localhost',
port: 8080 port: 8080
}) }
});
var proxyServer = http.createServer(function (req, res) {
proxy.proxyRequest(req, res);
}); });
// //
...@@ -83,11 +85,7 @@ proxyServer.on('upgrade', function (req, socket, head) { ...@@ -83,11 +85,7 @@ proxyServer.on('upgrade', function (req, socket, head) {
var buffer = httpProxy.buffer(socket); var buffer = httpProxy.buffer(socket);
setTimeout(function () { setTimeout(function () {
proxy.proxyWebSocketRequest(req, socket, head, { proxy.proxyWebSocketRequest(req, socket, head, buffer);
port: 8080,
host: 'localhost',
buffer: buffer
});
}, 1000); }, 1000);
}); });
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
var sys = require('sys'), var sys = require('sys'),
http = require('http'), http = require('http'),
colors = require('colors'), colors = require('colors'),
websocket = require('./../vendor/websocket'), websocket = require('../../vendor/websocket'),
httpProxy = require('../../lib/node-http-proxy'); httpProxy = require('../../lib/node-http-proxy');
try { try {
...@@ -67,12 +67,14 @@ socket.on('connection', function (client) { ...@@ -67,12 +67,14 @@ socket.on('connection', function (client) {
// //
// Setup our server to proxy standard HTTP requests // Setup our server to proxy standard HTTP requests
// //
var proxy = new httpProxy.HttpProxy(); var proxy = new httpProxy.HttpProxy({
var proxyServer = http.createServer(function (req, res) { target: {
proxy.proxyRequest(req, res, {
host: 'localhost', host: 'localhost',
port: 8080 port: 8080
}) }
});
var proxyServer = http.createServer(function (req, res) {
proxy.proxyRequest(req, res);
}); });
// //
...@@ -80,10 +82,7 @@ var proxyServer = http.createServer(function (req, res) { ...@@ -80,10 +82,7 @@ var proxyServer = http.createServer(function (req, res) {
// WebSocket requests as well. // WebSocket requests as well.
// //
proxyServer.on('upgrade', function (req, socket, head) { proxyServer.on('upgrade', function (req, socket, head) {
proxy.proxyWebSocketRequest(req, socket, head, { proxy.proxyWebSocketRequest(req, socket, head);
port: 8080,
host: 'localhost'
});
}); });
proxyServer.listen(8081); proxyServer.listen(8081);
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
var sys = require('sys'), var sys = require('sys'),
http = require('http'), http = require('http'),
colors = require('colors'), colors = require('colors'),
websocket = require('./../vendor/websocket'), websocket = require('../../vendor/websocket'),
httpProxy = require('../../lib/node-http-proxy'); httpProxy = require('../../lib/node-http-proxy');
try { try {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment