A lightweight HTTP tunneling solution built with Node.js and WebSockets.
Cube HTTP allows you to securely expose a local HTTP service to the internet through a single persistent WebSocket connection, similar to tools like ngrok but with a minimal self-hosted architecture.
- HTTP tunneling over WebSocket
- Self-hosted
- Token-based authentication
- Automatic reconnection with exponential backoff
- Health checks using WebSocket ping/pong
- Request and response streaming
- Simple deployment
- Zero external dependencies beyond Node.js packages
Internet
│
▼
+-------------+
| Cube Server |
+-------------+
│ WebSocket
▼
+-------------+
| Cube Client |
+-------------+
│
▼
Local Application
(127.0.0.1:PORT)
The server receives incoming HTTP requests and forwards them through a WebSocket tunnel to the client.
The client proxies those requests to a local HTTP service and sends the response back through the tunnel.
git clone https://github.com/mhyar-nsi/cube-http.git
cd cube-httpnpm installCreate a .env file:
TOKEN=my-secret-token
PORT=3000
PUBLIC_URL=https://example.comCreate a .env file:
TOKEN=my-secret-token
SERVER_ADDRESS=example.com:3000The TOKEN value must match on both sides.
cd servernode main.jsServer output:
Server listening on port 3000
Expose a local application running on port 8080:
cd clientnode main.js http 8080Example output:
Tunnel established: https://example.com
- User sends an HTTP request to the public URL.
- Cube Server receives the request.
- Server forwards the request through WebSocket.
- Cube Client receives the request.
- Client sends the request to the local service.
- Local service generates a response.
- Client sends the response back.
- Server returns the response to the user.
If the WebSocket connection is interrupted:
- The client automatically reconnects.
- Exponential backoff is used.
- Maximum retry delay is 30 seconds.
Authentication is performed immediately after connection:
{
"type": "auth",
"token": "your-secret-token"
}Connections with invalid tokens are rejected.
| Variable | Description |
|---|---|
| TOKEN | Authentication token |
| PORT | HTTP/WebSocket server port |
| PUBLIC_URL | Public tunnel URL |
| Variable | Description |
|---|---|
| TOKEN | Authentication token |
| SERVER_ADDRESS | Server address |
Local application:
localhost:5000Client:
cd clientnode main.js http 5000Public URL:
https://example.com
Requests to the public URL will now be forwarded to:
http://127.0.0.1:5000
MIT