How to use WebSockets with the Vercel adapter? #16652
Replies: 3 comments 3 replies
|
WebSocket support is in limbo, see #12973
|
|
Worth separating what's actually in limbo from what already exists. The Vercel platform side is real though, and it isn't Next.js-specific. import { experimental_upgradeWebSocket, type WebSocketData } from '@vercel/functions'
export async function GET() {
return experimental_upgradeWebSocket((ws) => {
ws.on('message', (data: WebSocketData) => {
ws.send(data)
})
})
}A SvelteKit For getting unblocked now rather than experimenting: deploy the socket.io server as its own separate Vercel Function (outside the SvelteKit build, or even a separate minimal Vercel project) using |
|
Short version: you cannot run a WebSocket server on Practical options:
So the app itself can stay on Vercel. The socket server just has to live somewhere persistent. |
Uh oh!
There was an error while loading. Please reload this page.
I would like to experiment with WebSockets. Our application is delpoyed using the official Vercel adapter.
Now that Vercel announced support for websockets, this made me think - is there an official way to use websockets in Sveltekit when using the Vercel adapter?
The end-goal would be to build something simple with socket.io, so we don't need a pusher subscription.
All reactions