next-http-proxy-middleware
next-http-proxy-middleware copied to clipboard
WebSocket doesn't work with Next framework.
I'm trying to use websocket with next-http-proxy-middleware, and it doesn't connect to my server, it just keeps the connection pending
next path: 'src/pages/api/[...all].ts'
import NextHttpProxyMiddleware from 'next-http-proxy-middleware'
import { NextApiRequest, NextApiResponse } from 'next/types'
export default (req: NextApiRequest, res: NextApiResponse) => NextHttpProxyMiddleware(req, res, {
target: 'http://localhost:2000',
ws: true
})
socket.io path: '/api/socket'
I'm also having the same problem. Only polling works, ws or wss protocol doesn't work.
Hi @leonardossss
Unfortunately, Nextjs doesn't handle the ws
(weboscket) scheme, so the client request cannot reach this middleware.
So, as @murilob1337 said, you should use HTTP polling (supported by some libraries like socket.io) instead of websockets.
Please let me know if I'm not understanding something
Is there any way to do proxy websocket
? , such as replacing the code in node_modules/next
Any solution?
@StringKe @TopCommit Hi there I checked your comment late. Sorry. Unfortunately, as far as I know, there is no official way to support Next.js.