Skip to content

Server Crashed after [HPM] Upgrading to WebSocket socket error #777

Open
@whatwewant

Description

@whatwewant

Checks

Describe the bug (be clear and concise)

10531652080005_ pic

Step-by-step reproduction instructions

1. Proxy Websocket Broken

Expected behavior (be clear and concise)

Server not crashed, just log errors

How is http-proxy-middleware used in your project?

const { createProxyMiddleware } = require('http-proxy-middleware');

...
createProxyMiddleware({
  target: `http://127.0.0.1:${this.port}/`,
  changeOrigin: true,
  ws: true,
  router: (req) => {
    const url = req.url;
    if (url.startsWith('/xxx')) {
      return null;
    }
    const result = this.router(url, this.url, this.port);
    if (result) {
      return result;
    }
    if (url.startsWith('/v1')) {
      return this.url;
    }
    return `http://127.0.0.1:${this.port}/`;
  },
})
...


### What http-proxy-middleware configuration are you using?

```typescript
{
  target: `http://127.0.0.1:${this.port}/`,
  changeOrigin: true,
  ws: true,
  router: (req) => {
    const url = req.url;
    if (url.startsWith('/xxx')) {
      return null;
    }
    const result = this.router(url, this.url, this.port);
    if (result) {
      return result;
    }
    if (url.startsWith('/v1')) {
      return this.url;
    }
    return `http://127.0.0.1:${this.port}/`;
  },
}


### What OS/version and node/version are you seeing the problem?

```shell
Platform: darwin
Architecture: arm64
Kernal: 21.3.0
Node: v16.14.2
V8: 9.4.146.24-node.20
NPM: 6.14.16
Yarn: 1.22.18

Additional context (optional)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions