Skip to content

Misleading documentation for Websockets via .createServer #349

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 2 commits into from
Mar 9, 2013
Merged
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
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,26 @@ 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 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'),
Expand Down