Skip to content

Commit

Permalink
Fix regression where it always adds *.ddev.site to hosts (ddev#4563)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfay authored Jan 19, 2023
1 parent ae782af commit 1bebf06
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pkg/ddevapp/hostname_mgt.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/drud/ddev/pkg/output"
"github.com/drud/ddev/pkg/util"
goodhosts "github.com/goodhosts/hostsfile"
"net"
"os"
exec2 "os/exec"
"runtime"
Expand Down Expand Up @@ -81,6 +82,24 @@ func (app *DdevApp) AddHostsEntriesIfNeeded() error {
}

for _, name := range app.GetHostnames() {

// If we're able to resolve the hostname via DNS or otherwise we
// don't have to worry about this. This will allow resolution
// of *.ddev.site for example
if app.UseDNSWhenPossible && globalconfig.IsInternetActive() {
// If they have provided "*.<name>" then look up the suffix
checkName := strings.TrimPrefix(name, "*.")
hostIPs, err := net.LookupHost(checkName)

// If we had successful lookup and dockerIP matches
// with adding to hosts file.
if err == nil && len(hostIPs) > 0 && hostIPs[0] == dockerIP {
continue
}
}

// We likely won't hit the hosts.Has() as true because
// we already did a lookup. But check anyway.
exists, err := IsHostnameInHostsFile(name)
if exists {
continue
Expand Down

0 comments on commit 1bebf06

Please sign in to comment.