Skip to content

Use WebSocket and SSE

Use an HTTP tunnel for WebSocket upgrades and streaming server sent events.

Run a service on port 3000 with a WebSocket endpoint at /ws, an SSE endpoint at /events, or both. Use your actual endpoint paths in the examples.

Start the HTTP tunnel

npx tubu-cli http 3000 --domain my-stream.tubu.dev

No separate tunnel type or streaming option is required.

Verify WebSocket

After the tunnel is ready, open your browser developer console and connect:

const socket = new WebSocket("wss://my-stream.tubu.dev/ws");
socket.addEventListener("open", () => console.log("Connected"));
socket.addEventListener("message", (event) => console.log(event.data));

Expect Connected, then any messages your service sends. Browser WebSocket and EventSource APIs cannot set an arbitrary X-Tubu-Auth header. For a protected tunnel, use a client that can supply the header, or use application authentication appropriate for your browser client.

Verify SSE

curl --no-buffer https://my-stream.tubu.dev/events

Expect events as your service emits them.