Add --slug flag to reuse a specific subdomain across sessions

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jose Luis Montañes Ojados
2026-02-09 01:27:17 +01:00
parent c83fa3530d
commit 803b4049a6
4 changed files with 68 additions and 31 deletions

View File

@@ -21,26 +21,28 @@ func logToFile(msg string) {
// Client handles the SSH connection and forwarding
type Client struct {
ServerAddr string
LocalPort string
AuthToken string
HostHeader string // New field for custom Host header
LocalHTTPS bool // New field: connect to local service with HTTPS
SSHClient *ssh.Client
Listener net.Listener
Events chan string // Channel to send logs/events to TUI
Metrics chan int64 // Channel to send bytes transferred
PublicURL string // PublicURL is the URL accessible from the internet
ServerAddr string
LocalPort string
AuthToken string
HostHeader string // Custom Host header
LocalHTTPS bool // Connect to local service with HTTPS
Slug string // Requested slug (empty = server assigns random)
SSHClient *ssh.Client
Listener net.Listener
Events chan string // Channel to send logs/events to TUI
Metrics chan int64 // Channel to send bytes transferred
PublicURL string // PublicURL is the URL accessible from the internet
stopKeepAlive chan struct{} // Signal to stop keepalive goroutine
}
func NewClient(serverAddr, localPort, authToken, hostHeader string, localHTTPS bool) *Client {
func NewClient(serverAddr, localPort, authToken, hostHeader string, localHTTPS bool, slug string) *Client {
return &Client{
ServerAddr: serverAddr,
LocalPort: localPort,
AuthToken: authToken,
HostHeader: hostHeader,
LocalHTTPS: localHTTPS,
Slug: slug,
Events: make(chan string, 10),
Metrics: make(chan int64, 10),
}
@@ -64,6 +66,20 @@ func (c *Client) connect() error {
c.SSHClient = client
c.Events <- "SSH Connected!"
// Request a specific slug if provided
if c.Slug != "" {
ok, reply, err := client.SendRequest("grokway-request-slug", true, []byte(c.Slug))
if err != nil || !ok {
reason := string(reply)
if reason == "" && err != nil {
reason = err.Error()
}
c.Events <- fmt.Sprintf("Slug %q not available (%s), server will assign one", c.Slug, reason)
} else {
c.Events <- fmt.Sprintf("Slug %q reserved", c.Slug)
}
}
// Request remote listening (Reverse Forwarding)
// Bind to 0.0.0.0 on server, random port (0)
listener, err := client.Listen("tcp", "0.0.0.0:0")