Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.
Merged
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
22 changes: 15 additions & 7 deletions internal/dev/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type Server struct {
connectionFailed time.Time
connectionStarted time.Time
reconnectMutex sync.Mutex
hostname string
}

type ServerArgs struct {
Expand Down Expand Up @@ -98,6 +99,7 @@ type ConnectionResponse struct {
ExpiresAt string `json:"expires_at"`
OtelUrl string `json:"otlp_url"`
OtelBearerToken string `json:"otlp_token"`
Hostname string `json:"hostname,omitempty"`
} `json:"data"`
}

Expand Down Expand Up @@ -145,6 +147,7 @@ func (s *Server) refreshConnection() error {
s.logger = logger
s.cleanup = cleanup
}
s.hostname = resp.Data.Hostname

return nil
}
Expand Down Expand Up @@ -210,18 +213,23 @@ func (s *Server) connect(initial bool) {
tlsConfig.Certificates = []tls.Certificate{*s.tlsCertificate}
tlsConfig.NextProtos = []string{"h2"}

if strings.Contains(s.serverAddr, "localhost") || strings.Contains(s.serverAddr, "127.0.0.1") {
hostname := s.hostname
if hostname == "" {
hostname = s.serverAddr
}

if strings.Contains(hostname, "localhost") || strings.Contains(hostname, "127.0.0.1") {
tlsConfig.InsecureSkipVerify = true
}

if !strings.Contains(s.serverAddr, ":") {
s.serverAddr = fmt.Sprintf("%s:443", s.serverAddr)
if !strings.Contains(hostname, ":") {
hostname = fmt.Sprintf("%s:443", hostname)
}

conn, err := tls.Dial("tcp", s.serverAddr, &tlsConfig)
conn, err := tls.Dial("tcp", hostname, &tlsConfig)
if err != nil {
gerr = err
s.logger.Warn("failed to dial tls: %s, will retry ...", err)
s.logger.Warn("failed to dial devmode server: %s (%s), will retry ...", hostname, err)
return
}
s.conn = conn
Expand All @@ -241,7 +249,7 @@ func (s *Server) connect(initial bool) {
s.connectionFailed = time.Time{}
s.reconnectMutex.Unlock()

s.logger.Debug("connection established to %s", s.serverAddr)
s.logger.Debug("connection established to %s", hostname)

// HTTP/2 server to accept proxied requests over the tunnel connection
h2s := &http2.Server{}
Expand Down Expand Up @@ -428,7 +436,7 @@ func (s *Server) handleStream(w http.ResponseWriter, r *http.Request) {
err = fmt.Errorf("failed to insert project id into trace state: %w", err)
return
}
traceState, err = traceState.Insert("d", "1");
traceState, err = traceState.Insert("d", "1")
if err != nil {
logger.Error("failed to insert devmode status into trace state: %s", err)
err = fmt.Errorf("failed to insert devmode status into trace state: %w", err)
Expand Down
Loading