Skip to content
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

fix(ws): internal server upgrade #357

Merged
merged 1 commit into from Sep 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
@@ -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
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
@@ -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
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