Skip to content

Forward WebSockets from Vite tunnels#30

Draft
mmkal wants to merge 1 commit into
mainfrom
vite-websocket-forwarding
Draft

Forward WebSockets from Vite tunnels#30
mmkal wants to merge 1 commit into
mainfrom
vite-websocket-forwarding

Conversation

@mmkal

@mmkal mmkal commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Makes the captun/vite plugin forward WebSocket upgrades to the local Vite server, instead of only forwarding plain HTTP.

This lets browser clients use the public tunnel URL for Vite HMR and other WebSocket endpoints served by the same dev server.

pkg.pr.new package for testing:

pnpm add https://pkg.pr.new/captun@6aa1207

Note: use the commit alias above. The PR-number alias currently resolves to an older package artifact.

Changes

  • Passes connectWebSocket to createCaptunTunnel from the Vite plugin.
  • Dials the local Vite server with the tunneled pathname/search and maps http/https targets to ws/wss.
  • Forwards application handshake headers while leaving hop-by-hop and sec-websocket-* headers for the local WebSocket client to negotiate.
  • Adds a regression test that connects through a captun tunnel to Vite's own HMR socket and receives the normal connected payload.

Verification

  • pnpm exec vitest run test/vite-plugin.test.ts
  • pnpm run typecheck
  • pnpm exec oxfmt --check src/vite.ts test/vite-plugin.test.ts
  • pnpm run lint
  • pnpm run build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant