From ee6bbe00244c90bd532b11ff1c796aea8c7372f8 Mon Sep 17 00:00:00 2001 From: jamie-stackhouse Date: Fri, 22 Feb 2013 09:59:16 -0400 Subject: [PATCH 1/2] Change wording for handling websocket proxy events --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fdedc3aba..73912e541 100644 --- a/README.md +++ b/README.md @@ -411,7 +411,7 @@ httpProxy.createServer( ``` ## Proxying WebSockets -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: +Websockets are handled automatically when using `httpProxy.createServer()`, however, if you supply a callback inside the createServer call, you will need to handle the 'upgrade' proxy event yourself. Here's how: ``` js var http = require('http'), From 603106a13d28c0199fa4456cc9aee1692eb2588c Mon Sep 17 00:00:00 2001 From: jamie-stackhouse Date: Fri, 22 Feb 2013 10:31:44 -0400 Subject: [PATCH 2/2] Re-added previous description --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index 73912e541..53d9c1203 100644 --- a/README.md +++ b/README.md @@ -413,6 +413,25 @@ httpProxy.createServer( ## Proxying WebSockets Websockets are handled automatically when using `httpProxy.createServer()`, however, if you supply a callback inside the createServer call, you will need to handle the 'upgrade' proxy event yourself. Here's how: +```js + +var options = { + .... +}; + +var server = httpProxy.createServer( + callback/middleware, + options +); + +server.listen(port, function() { ... }); +server.on('upgrade', function(req, socket, head) { + server.proxy.proxyWebSocketRequest(req, socket, head); +}); +``` + +If you would rather not use createServer call, and create the server that proxies yourself, see below: + ``` js var http = require('http'), httpProxy = require('http-proxy');