PRO

WebSocket Route Handler

Native WebSocket upgrade support in a Next.js route handler via NextResponse.upgrade(), powered by crossws (bundled with Next.js, no extra install). Requires the experimental.webSocketRouteHandlers flag in next.config.ts; Node.js runtime only, not supported on Edge, static export, or Vercel Functions.

Install
npx shadcn@latest add https://ui.aryank.space/r/websocket-route-handler.json

Installs from ui.aryank.space. To add it by hand, copy the files in Files below, or register the @compronents namespace via the docs.

Visualization
upgrade
Request
socket
unknown
return NextResponse.upgrade({ open(peer) { peer.send(welcome) } })

A Next.js route handler upgrades to WebSocket via NextResponse.upgrade() on the Node runtime, powered by the bundled crossws, no extra install.

Files

Dependencies
None.