Skip to content

Commit c686ac7

Browse files
committed
Merge pull request #349 from jamie-stackhouse/patch-1
Misleading documentation for Websockets via .createServer
2 parents 26d3646 + 603106a commit c686ac7

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

README.md

+20-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,26 @@ httpProxy.createServer(
411411
```
412412

413413
## Proxying WebSockets
414-
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:
414+
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:
415+
416+
```js
417+
418+
var options = {
419+
....
420+
};
421+
422+
var server = httpProxy.createServer(
423+
callback/middleware,
424+
options
425+
);
426+
427+
server.listen(port, function() { ... });
428+
server.on('upgrade', function(req, socket, head) {
429+
server.proxy.proxyWebSocketRequest(req, socket, head);
430+
});
431+
```
432+
433+
If you would rather not use createServer call, and create the server that proxies yourself, see below:
415434

416435
``` js
417436
var http = require('http'),

0 commit comments

Comments
 (0)