1
Fork 0
mirror of https://github.com/benkoppe/traforo synced 2026-03-09 23:57:14 -07:00
No description
  • TypeScript 95.2%
  • HTML 3.1%
  • JavaScript 1.7%
Find a file
Tommy D. Rossi 2949832dfa fix: WebSocket subprotocol and query param proxying, add Vite HMR test
Three bugs fixed in the tunnel proxy:

1. _tunnelId query param leaked into every HTTP request forwarded to the
   local server (e.g. /counter.ts?_tunnelId=xxx). Now stripped before
   building the proxy path.

2. WebSocket proxy dropped query params from the path — Vite HMR needs
   ?token=xxx to authenticate, which was silently lost. Now forwarded
   (minus _tunnelId).

3. DO did not echo Sec-WebSocket-Protocol in the 101 response, and the
   client did not forward the subprotocol when opening the local WS.
   Strict clients (ws library, Vite) rejected the connection. Now the DO
   echoes the protocol and the client forwards it to the local server.

Added Vite HMR integration test that starts a Vite dev server, tunnels
it through the preview deployment, and verifies:
- HTML page loads through tunnel
- Module requests work through tunnel
- HMR WebSocket connects with vite-hmr protocol and receives
  full-reload messages when a .ts file is modified
- Updated module content is served after file change

Also fixed a pre-existing test that checked for lowercase 'offline' in
the offline HTML page which uses 'Tunnel Offline' (capital O).
2026-02-19 08:57:46 +01:00
example-static initial commit 2026-01-31 13:27:36 +01:00
public remove --domain flag, reduce landing page max-width 2026-01-31 14:30:44 +01:00
src fix: WebSocket subprotocol and query param proxying, add Vite HMR test 2026-02-19 08:57:46 +01:00
.gitignore fix: WebSocket subprotocol and query param proxying, add Vite HMR test 2026-02-19 08:57:46 +01:00
CHANGELOG.md fix: remove CORS injection, preserve multi-value Set-Cookie headers 2026-02-07 09:31:49 +01:00
package.json fix: WebSocket subprotocol and query param proxying, add Vite HMR test 2026-02-19 08:57:46 +01:00
README remove --domain flag, reduce landing page max-width 2026-01-31 14:30:44 +01:00
tsconfig.client.json initial commit 2026-01-31 13:27:36 +01:00
tsconfig.json initial commit 2026-01-31 13:27:36 +01:00
tsconfig.test.json initial commit 2026-01-31 13:27:36 +01:00
vitest.config.ts initial commit 2026-01-31 13:27:36 +01:00
wrangler.json initial commit 2026-01-31 13:27:36 +01:00

TRAFORO
=======

HTTP tunnel via Cloudflare Durable Objects and WebSockets.
Expose local servers to the internet with a simple CLI.


INSTALLATION
------------

    npm install -g traforo


USAGE
-----

Expose a local server:

    traforo -p 3000

With a custom tunnel ID:

    traforo -p 3000 -t my-app

Run a command and tunnel it:

    traforo -p 3000 -- next start
    traforo -p 3000 -- pnpm dev
    traforo -p 5173 -- vite

The tunnel URL will be:

    https://{tunnel-id}-tunnel.traforo.dev


OPTIONS
-------

    -p, --port <port>       Local port to expose (required)
    -t, --tunnel-id [id]    Tunnel ID (random if omitted)
    -h, --host [host]       Local host (default: localhost)
    -s, --server [url]      Custom tunnel server URL
    --help                  Show help
    --version               Show version


HOW IT WORKS
------------

1. Local client connects to Cloudflare Durable Object via WebSocket
2. HTTP requests to tunnel URL are forwarded to the DO
3. DO sends requests over WebSocket to local client
4. Local client makes request to localhost and returns response
5. WebSocket connections from users are also proxied through


API ENDPOINTS
-------------

    /traforo-status         Check if tunnel is online
    /traforo-upstream       WebSocket endpoint for local client
    /*                      All other paths proxied to local server


LIBRARY USAGE
-------------

    import { TunnelClient } from 'traforo/client'
    import { runTunnel } from 'traforo/run-tunnel'

    const client = new TunnelClient({
      localPort: 3000,
      tunnelId: 'my-app',
    })

    await client.connect()


LICENSE
-------

MIT