Open ldej opened 1 year ago
I have the same problem, Next.js does not behave well as a websocket proxy
Just so this thread doesn't self resolve. I have this same issue too
@anthonytranDev this workaround might interest you, https://github.com/vercel/next.js/discussions/58698#discussioncomment-7655962
Checks
http-proxy-middleware
.Describe the bug (be clear and concise)
I have used the recipe for next.js and API routes: https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/servers.md#nextjs
When I enable
ws: true
, it proxies my websocket request successfully. However, when I refresh the page, 2 websocket requests are made to the server, resulting inInvalid frame header
errors. When I refresh the page again, 3 websocket requests are made, and so on.I have the feeling that a new
server.on('upgrade'
events is registered whenever.Step-by-step reproduction instructions
Expected behavior (be clear and concise)
I would expect that
http-proxy-middleware
would not create multiple websockets when I create 1 websocket.How is http-proxy-middleware used in your project?
What http-proxy-middleware configuration are you using?
What OS/version and node/version are you seeing the problem?
Additional context (optional)
For now, changing the handler to read from a global variable works:
Any suggestions?