Adding support for tunneling with bore, localtunnel, and ngrok

pull/44/head
Tom Chapin 11 months ago
parent 859328da05
commit 298059b9c4

@ -11,14 +11,31 @@ pip install 01OS
**Expose an 01 server publically:**
We are currently using localtunnel (https://github.com/localtunnel/localtunnel) to handle the creation of public tunnel endpoints.
We currently support exposing the 01 server publicly via a couple of different tunnel services:
Note: You will need to install Node and localtunnel before exposing the service will work correctly:
```npm install -g localtunnel```
- bore.pub (https://github.com/ekzhang/bore)
Requirements: Ensure that rust is installed (https://www.rust-lang.org/tools/install), then run `cargo install bore-cli`
```bash
01 --server --expose-with-bore
```
- localtunnel (https://github.com/localtunnel/localtunnel)
Requirements: Ensure that Node is installed (https://nodejs.org/en/download), then run `npm install -g localtunnel`
```bash
01 --server --expose-with-localtunnel
```
- ngrok (https://ngrok.com/)
Requirements: Install ngrok (https://ngrok.com/docs/getting-started/), and set up an ngrok account.
Get your auth key from https://dashboard.ngrok.com/get-started/your-authtoken, then set it in
your local configuration by running `ngrok config add-authtoken your_auth_token_here`
```bash
01 --server --expose-with-ngrok
```
```bash
01 --server --expose # This will print a URL that a client can point to.
```
**Run a specific client:**
@ -34,5 +51,5 @@ The `--local` flag will install and run the [whisper.cpp](https://github.com/gge
```bash
01 --local # Local client and server
01 --local --server --expose # Expose a local server
01 --local --server --expose-with-bore # Expose a local server
```

@ -61,6 +61,16 @@ if [[ "$@" == *"--expose"* ]]; then
exit 1
else
export TUNNEL_START="True"
if [[ "$@" == *"--expose-with-bore"* ]]; then
export TUNNEL_METHOD="bore"
elif [[ "$@" == *"--expose-with-localtunnel"* ]]; then
export TUNNEL_METHOD="localtunnel"
elif [[ "$@" == *"--expose-with-ngrok"* ]]; then
export TUNNEL_METHOD="ngrok"
fi
echo "exposing server"
fi
fi

@ -1,14 +1,65 @@
#!/usr/bin/env bash
# Get tunnel method from TUNNEL_METHOD environment variable, but default to bore
# Possible options;
# - bore
# - localtunnel
# - ngrok
TUNNEL_METHOD=${TUNNEL_METHOD:-bore}
# Get the SERVER_PORT environment variable, but default to 8000
SERVER_LOCAL_PORT=${SERVER_LOCAL_PORT:-8000}
echo "Starting up localtunnel service for port $SERVER_LOCAL_PORT on localhost..."
echo "Using $TUNNEL_METHOD to expose port $SERVER_LOCAL_PORT on localhost..."
# If the TUNNEL_METHOD is bore, then we need to check if the bore-cli is installed
if [[ "$TUNNEL_METHOD" == "bore" ]]; then
if ! command -v bore &> /dev/null; then
echo "The bore-cli command is not available. Please run 'cargo install bore-cli'."
echo "For more information, see https://github.com/ekzhang/bore"
exit 1
else
bore local $SERVER_LOCAL_PORT --to bore.pub | while IFS= read -r line; do
if [[ "$line" == *"listening at bore.pub:"* ]]; then
remote_port=$(echo "$line" | grep -o 'bore.pub:[0-9]*' | cut -d':' -f2)
echo "Please set your client env variable for SERVER_URL=ws://bore.pub:$remote_port"
break
fi
done
fi
elif [[ "$TUNNEL_METHOD" == "localtunnel" ]]; then
npx localtunnel --port $SERVER_LOCAL_PORT | while IFS= read -r line; do
if [[ "$line" == "your url is: https://"* ]]; then
echo "Tunnel is up!"
echo "Please set your client env variable for SERVER_URL=wss://${line:21}"
break
if ! command -v lt &> /dev/null; then
echo "The 'lt' command is not available."
echo "Please ensure you have Node.js installed, then run 'npm install -g localtunnel'."
echo "For more information, see https://github.com/localtunnel/localtunnel"
exit 1
else
npx localtunnel --port $SERVER_LOCAL_PORT | while IFS= read -r line; do
if [[ "$line" == *"your url is: https://"* ]]; then
remote_url=$(echo "$line" | grep -o 'https://[a-zA-Z0-9.-]*' | sed 's|https://||')
echo "Please set your client env variable for SERVER_URL=wss://$remote_url"
break
fi
done
fi
done
elif [[ "$TUNNEL_METHOD" == "ngrok" ]]; then
if ! command -v ngrok &> /dev/null; then
echo "The ngrok command is not available."
echo "Please install ngrok using the instructions at https://ngrok.com/docs/getting-started/"
exit 1
else
ngrok http $SERVER_LOCAL_PORT --log stdout | while IFS= read -r line; do
if [[ "$line" == *"started tunnel"* ]]; then
remote_url=$(echo "$line" | grep -o 'https://[a-zA-Z0-9.-]*' | sed 's|https://||')
echo "Please set your client env variable for SERVER_URL=wss://$remote_url"
break
fi
done
fi
fi

Loading…
Cancel
Save