Skip to content

Commit

Permalink
fix(ws): internal server upgrade (#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
chimurai authored Sep 3, 2019
1 parent 616f60f commit 3b97308
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Changelog

## next
## [v0.20.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.20.0)

- fix(ws): concurrent websocket requests do not get upgraded ([#335](https://github.com/chimurai/http-proxy-middleware/issues/335))
- chore: drop node 6 (BREAKING CHANGE)
- chore: update to micromatch@4 ([BREAKING CHANGE](https://github.com/micromatch/micromatch/blob/master/CHANGELOG.md#400---2019-03-20))
- chore: update dev dependencies
Expand Down
4 changes: 2 additions & 2 deletions examples/websocket/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ <h2>WebSocket demo</h2>

function connect() {
setupSocket(location.value);
toggleControls();
}

function disconnect() {
socket.close();
socket = undefined;
toggleControls();
}

function sendMessage(val) {
Expand All @@ -83,11 +85,9 @@ <h2>WebSocket demo</h2>
socket = new WebSocket(url);
socket.addEventListener('open', () => {
log('CONNECTED');
toggleControls();
})
socket.addEventListener('close', () => {
log('DISCONNECTED');
toggleControls()
})
socket.addEventListener('error', () => { log('SOCKET ERROR OCCURED'); })
socket.addEventListener('message', (msg) => { log('RECEIVED:' + msg.data); })
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "http-proxy-middleware",
"version": "0.20.0-beta.2",
"version": "0.20.0",
"description": "The one-liner node.js proxy middleware for connect, express and browser-sync",
"main": "dist/index.js",
"files": [
Expand Down
10 changes: 6 additions & 4 deletions src/http-proxy-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ export class HttpProxyMiddleware {
};

private catchUpgradeRequest = server => {
server.on('upgrade', this.handleUpgrade);
// prevent duplicate upgrade handling;
// in case external upgrade is also configured
this.wsInternalSubscribed = true;
if (!this.wsInternalSubscribed) {
server.on('upgrade', this.handleUpgrade);
// prevent duplicate upgrade handling;
// in case external upgrade is also configured
this.wsInternalSubscribed = true;
}
};

private handleUpgrade = (req, socket, head) => {
Expand Down

0 comments on commit 3b97308

Please sign in to comment.