cmd/hello: serve fake data in dev mode on whois failure
parent
de3001bc79
commit
34ffd4f7c6
|
@ -108,18 +108,30 @@ func root(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
who, err := whoIs(ip)
|
who, err := whoIs(ip)
|
||||||
|
var data tmplData
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("whois(%q) error: %v", ip, err)
|
if devMode() {
|
||||||
http.Error(w, "Your Tailscale works, but we failed to look you up.", 500)
|
data = tmplData{
|
||||||
return
|
DisplayName: "Taily Scalerson",
|
||||||
|
LoginName: "taily@scaler.son",
|
||||||
|
MachineName: "scaled",
|
||||||
|
IP: "100.1.2.3",
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.Printf("whois(%q) error: %v", ip, err)
|
||||||
|
http.Error(w, "Your Tailscale works, but we failed to look you up.", 500)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
data = tmplData{
|
||||||
|
DisplayName: who.UserProfile.DisplayName,
|
||||||
|
LoginName: who.UserProfile.LoginName,
|
||||||
|
MachineName: who.Node.ComputedName,
|
||||||
|
IP: ip,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
tmpl.Execute(w, tmplData{
|
tmpl.Execute(w, data)
|
||||||
DisplayName: who.UserProfile.DisplayName,
|
|
||||||
LoginName: who.UserProfile.LoginName,
|
|
||||||
MachineName: who.Node.ComputedName,
|
|
||||||
IP: ip,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// tsSockClient does HTTP requests to the local Tailscale daemon.
|
// tsSockClient does HTTP requests to the local Tailscale daemon.
|
||||||
|
|
Loading…
Reference in New Issue