Skip to content

Commit

Permalink
Fixed macOS Bonjour 5-second delay
Browse files Browse the repository at this point in the history
  • Loading branch information
eko committed Oct 27, 2023
1 parent 84668bf commit 5d3161f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/proxy/proxy.go
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"
"net"
"runtime"
"strconv"
"sync"

Expand Down Expand Up @@ -185,6 +186,17 @@ func (p *proxy) generateIP(pf *ProxyForward) error {
pf.SetLocalIP(ip.String())
p.attributedIPs[pf.GetHostname()] = ip.String()

// To avoid a 5 second delay on macOS, we add the hostname to the hosts file.
// This is not the best solution but it works for now.
// @see: https://stackoverflow.com/questions/6841421/mac-osx-lion-dns-lookup-order
switch runtime.GOOS {
case "darwin":
err = p.hostfile.AddHost("::1", pf.GetHostname())
if err != nil {
p.view.Writef("❌ An error has occured while trying to write host file for application '%s' (ip: %s): %v\n", pf.Name, pf.LocalIP, err)
}
}

err = p.hostfile.AddHost(pf.LocalIP, pf.GetHostname())
if err != nil {
p.view.Writef("❌ An error has occured while trying to write host file for application '%s' (ip: %s): %v\n", pf.Name, pf.LocalIP, err)
Expand Down

0 comments on commit 5d3161f

Please sign in to comment.