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

websocket path is wrong after createProxyMiddleware #858

Open
2 tasks done
alanhe421 opened this issue Dec 4, 2022 · 0 comments
Open
2 tasks done

websocket path is wrong after createProxyMiddleware #858

alanhe421 opened this issue Dec 4, 2022 · 0 comments

Comments

@alanhe421
Copy link

Checks

Describe the bug (be clear and concise)

const jsonPlaceholderProxy = createProxyMiddleware({
  target: 'http://127.0.0.1:36001',
  ws: true, changeOrigin: true,
  agent: proxyServer.agent,
  logger: console,
  secure: false,
  pathRewrite: function (path, req) {
    let newPath = path.replace('/tty/9df90607382c056d8312cb77e368aa03', '');
    // if (newPath.indexOf('.websocket') > -1) {
    //   newPath = newPath.replace('/.websocket', '');
    // }
    console.log('newPath', newPath);
    return newPath
  }
  
});

for ws connection.

the correct path is /stable-129500ee4c8ab7263461ffe327268ba56b9f210d?reconnectionToken=2ba87094-7ef8-4dd6-93dc-70f36a7d9f74&reconnection=false&skipWebSocketFrames=false

but output /stable-129500ee4c8ab7263461ffe327268ba56b9f210d/.websocket?reconnectionToken=2ba87094-7ef8-4dd6-93dc-70f36a7d9f74&reconnection=false&skipWebSocketFrames=false
the page i visit is
ws://127.0.0.1:8000/tty/9df90607382c056d8312cb77e368aa03/stable-129500ee4c8ab7263461ffe327268ba56b9f210d?reconnectionToken=d1dc2f35-4826-4920-a576-1204ce54b951&reconnection=false&skipWebSocketFrames=false

/.websocket is wrong??

Step-by-step reproduction instructions

just like the code snippet?

Expected behavior (be clear and concise)

path is correct.

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

express-demo@0.0.1 /Users/alanhe/GitHub/express-demo
└── http-proxy-middleware@2.0.6

What http-proxy-middleware configuration are you using?

const jsonPlaceholderProxy = createProxyMiddleware({
  target: 'http://127.0.0.1:36001',
  ws: true, changeOrigin: true,
  agent: proxyServer.agent,
  logger: console,
  secure: false,
  pathRewrite: function (path, req) {
    let newPath = path.replace('/tty/9df90607382c056d8312cb77e368aa03', '');
    // if (newPath.indexOf('.websocket') > -1) {
    //   newPath = newPath.replace('/.websocket', '');
    // }
    console.log('newPath', newPath);
    return newPath
  }
});

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

1. Big Sur 11.7
2. node.js@14.18.0

Additional context (optional)

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant