chimurai / http-proxy-middleware

:zap: The one-liner node.js http-proxy middleware for connect, express, next.js and more
MIT License
10.68k stars 826 forks source link

Proxy created with websocket stops working after a few minutes #884

Closed hayzamjs closed 1 year ago

hayzamjs commented 1 year ago

Checks

Describe the bug (be clear and concise)

I have an instance of ttyd that is already reverse proxied by nginx at the URL https://192.168.1.1:4443/ttyd and that is available and functional when I visit it. My end goal is to have this instance in an iframe in one of my web applications that uses node.js and express as the web framework.

This is how I create the proxy:

const ttydProxy = createProxyMiddleware({
  target: `https://192.168.1.1:4443/ttyd`,
  changeOrigin: true,
  ws: true,
  secure: false,
  logLevel: 'silent',
  pathRewrite: {
    '^/ttyd': ''
  },
  onProxyReq: fixRequestBody
})

And I use it with the express app like this:

app.use(['/ttyd', '/ttyd/*'], [ensureAuthenticated, ttydProxy])

Everything works well, atleast for a few minutes i.e before my browser starts showing this in the console with the iframe in question:

image

I'm not sure if it's something to do with my setup or something else entirely, would love some pointers in the right direction if it is indeed my fault

Step-by-step reproduction instructions

Try with the config I've mentioned in the description that should be able to reproduce the issue

Expected behavior (be clear and concise)

Websocket should be able to connect even after a long period of inactivity

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

app@0.0.1 /www/app
`-- http-proxy-middleware@2.0.6

What http-proxy-middleware configuration are you using?

const ttydProxy = createProxyMiddleware({
  target: `https://192.168.1.1:4443/ttyd`,
  changeOrigin: true,
  ws: true,
  secure: false,
  logLevel: 'silent',
  pathRewrite: {
    '^/ttyd': ''
  },
  onProxyReq: fixRequestBody
})

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

OpenWRT Linux 22.04, NodeJS v16.17.1

Additional context (optional)

No response