Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ Now you can visit [localhost:3000](localhost:3000) in your browser and start usi

</details>

# Ngrok Tunneling Setup

To enable ngrok tunneling for local development and testing, follow these steps:

1. Obtain an ngrok auth token by signing up at [ngrok.com](https://ngrok.com/).
2. Configure the `.env` file in the `backend` directory with your ngrok auth token and desired tunnel name:
```
NGROK_AUTH_TOKEN=your_ngrok_auth_token
NGROK_TUNNEL_NAME=your_desired_tunnel_name
```
3. Start the ngrok tunnel to expose your local development server to the internet. The exposed URL will be displayed in the terminal.

This setup allows you to test your local development server from external devices and share your work with others without deploying it.

# Development

Check out the [DEVELOPMENT.md](./DEVELOPMENT.md) for more information.
Expand Down
4 changes: 4 additions & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ OLLAMA_MODEL=
# Goose
GOOSE_DRIVER=
GOOSE_DBSTRING=

# Ngrok
NGROK_AUTH_TOKEN=
NGROK_TUNNEL_NAME=
23 changes: 21 additions & 2 deletions backend/executor/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import (
"github.com/docker/docker/api/types"
"github.com/semanser/ai-coder/database"
gmodel "github.com/semanser/ai-coder/graph/model"
"github.com/semanser/ai-coder/graph/subscriptions"
"github.com/semanser/ai-coder/websocket"
"github.com/ngrok/ngrok-api-go"
)

var ngrokAuthToken = "your_ngrok_auth_token" // Placeholder for ngrok auth token

func ExecCommand(flowID int64, command string, db *database.Queries) (result string, err error) {
container := TerminalName(flowID)

Expand Down Expand Up @@ -189,5 +191,22 @@ func WriteFile(flowID int64, content string, path string, db *database.Queries)
}

func TerminalName(flowID int64) string {
return fmt.Sprintf("codel-terminal-%d", flowID)
// Initialize ngrok with the specified auth token
ngrokClient := ngrok.NewClient(ngrokAuthToken)

// Create or retrieve an ngrok tunnel
tunnel, err := ngrokClient.Tunnels.GetOrCreate(context.Background(), &ngrok.TunnelCreate{
Name: fmt.Sprintf("codel-terminal-%d", flowID),
Addr: fmt.Sprintf("http://localhost:%d", flowID), // Assuming the service runs on a port that matches the flowID
Proto: "http",
Region: "us",
Auth: "",
BinAddr: "",
BindTLS: true,
})
if err != nil {
log.Fatalf("Failed to create or retrieve ngrok tunnel: %v", err)
}

return tunnel.PublicURL // Use ngrok tunnel URL
}