@sundaysf/tunnel
v1.0.0
Published
Tunnel SDK for exposing local servers to the internet
Maintainers
Readme
@sundaysf/tunnel
A tunneling SDK that exposes your local servers to the internet, similar to ngrok.
Installation
npm install -g @sundaysf/tunnelGetting Started
1. Get an API Key
First, you need to get an API key from the Dolphin Tunnel dashboard:
- Go to http://localhost:3000
- Sign up or log in
- Navigate to Dashboard > API Tokens
- Create a new API token
- Copy the token (it will only be shown once!)
2. Authenticate
Set up your API key with the stun CLI:
stun auth YOUR_API_KEYThis saves your API key locally for future use.
3. Create a Tunnel
Now you can create tunnels to expose your local servers:
stun http 3000This will create a tunnel from a public URL to your local server running on port 3000.
CLI Commands
Authentication
# Set your API key
stun auth YOUR_API_KEY
# Check current user
stun whoami
# Log out (clear credentials)
stun logoutTunnel Management
# Create HTTP tunnel
stun http 3000
# With custom subdomain
stun http 3000 -s myapp
# Forward to specific host
stun http 3000 -h 192.168.1.100
# List all your tunnels
stun listConfiguration
# Show current configuration
stun config --show
# Set custom server URL
stun config --set-server https://api.example.com
# Reset all configuration
stun config --resetCommand Options
http <port>- Start an HTTP tunnel to the specified port-s, --subdomain <subdomain>- Request a specific subdomain-h, --host <host>- Local host to forward to (default: localhost)-t, --token <token>- API token for authentication
Programmatic Usage
const { TunnelClient } = require('@sundaysf/tunnel');
const client = new TunnelClient({
serverUrl: 'https://api.tunnel.dolphintech.io',
apiToken: 'your-api-token'
});
async function startTunnel() {
const tunnel = await client.connect({
port: 3000,
host: 'localhost',
subdomain: 'myapp',
protocol: 'http'
});
console.log(`Tunnel URL: ${tunnel.url}`);
tunnel.on('request', (req) => {
console.log(`${req.method} ${req.path}`);
});
tunnel.on('error', (error) => {
console.error('Tunnel error:', error);
});
}
startTunnel();Features
- Fast WebSocket-based tunneling
- Custom subdomain support
- Real-time request logging
- Automatic reconnection
- Request/response forwarding
- Support for various content types
License
MIT
