Replies: 8 comments 15 replies
-
You can use http-proxy-middleware inside an API Route. This library supports proxying WebSockets if you enable the
|
Beta Was this translation helpful? Give feedback.
-
Does next.js now support websocket via api routes? Or does it require a http upgrade rather than ws protocol? |
Beta Was this translation helpful? Give feedback.
-
Something that never worked well in nextjs, very sad 😢 |
Beta Was this translation helpful? Give feedback.
-
I'm able to get the WebSocket proxy working in dev mode but it seems to stop working when I deploy to production on my own server using the node.js runtime. Config looks like this: // eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require("path");
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
output: "standalone",
experimental: {
serverActions: true,
outputFileTracingRoot: path.join(__dirname, "../../"),
},
async rewrites() {
return [
{
source: "/api/:path*",
destination: `http://0.0.0.0:49153/:path*`,
},
];
},
};
module.exports = nextConfig; |
Beta Was this translation helpful? Give feedback.
-
Same issue here, and I also use the app router. Did anyone get it to work on the app router? |
Beta Was this translation helpful? Give feedback.
-
I have a Nest.JS back-end and I use socket.io. I got it working with the following code, I'm using app directory in Next.JS, but for proxy, I'm using pages directory because of http-proxy-middleware src/pages/api/proxy/[...paths.ts]
// some-provider-component.tsx
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Describe the feature you'd like to request
websocket proxy is needed for many people
Describe the solution you'd like
websocket proxy is needed for many people
Describe alternatives you've considered
websocket proxy is needed for many people
Beta Was this translation helpful? Give feedback.
All reactions