From bb053d3c04762539451d4514de22f55d3c0f8cbc Mon Sep 17 00:00:00 2001 From: Martin Tournoij Date: Fri, 27 Mar 2020 18:09:30 +0800 Subject: [PATCH] Set DomainCount for serve too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In 59e851d we split out the static domain to gc.zgo.at and static.zgo.at, but this only worked for the saas command and not serve 😅 --- cmd/goatcounter/serve.go | 1 + handlers/backend.go | 27 +++++++++++++++++++++------ site.go | 4 ++-- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/cmd/goatcounter/serve.go b/cmd/goatcounter/serve.go index 91048fc02..55f7c9ebb 100644 --- a/cmd/goatcounter/serve.go +++ b/cmd/goatcounter/serve.go @@ -129,6 +129,7 @@ func serve() (int, error) { v.Domain("-domain", cfg.DomainStatic) } cfg.URLStatic = "//" + cfg.DomainStatic + cfg.DomainCount = cfg.DomainStatic } flagAuth(auth, &v) diff --git a/handlers/backend.go b/handlers/backend.go index 3c7e65208..386a5c032 100644 --- a/handlers/backend.go +++ b/handlers/backend.go @@ -336,6 +336,14 @@ func (h backend) index(w http.ResponseWriter, r *http.Request) error { return err } + cd := cfg.DomainCount + if cd == "" { + cd = goatcounter.MustGetSite(r.Context()).Domain() + if cfg.Port != "" { + cd += ":" + cfg.Port + } + } + x := zhttp.Template(w, "backend.gohtml", struct { Globals CountDomain string @@ -362,11 +370,10 @@ func (h backend) index(w http.ResponseWriter, r *http.Request) error { ShowMoreRefs bool Daily bool ForcedDaily bool - }{newGlobals(w, r), cfg.DomainCount, sr, r.URL.Query().Get("hl-period"), - start, end, filter, pages, morePages, refs, moreRefs, total, - totalDisplay, browsers, totalBrowsers, subs, sizeStat, totalSize, - locStat, totalLoc, showMoreLoc, topRefs, showMoreRefs, daily, - forcedDaily}) + }{newGlobals(w, r), cd, sr, r.URL.Query().Get("hl-period"), start, end, + filter, pages, morePages, refs, moreRefs, total, totalDisplay, browsers, + totalBrowsers, subs, sizeStat, totalSize, locStat, totalLoc, + showMoreLoc, topRefs, showMoreRefs, daily, forcedDaily}) l = l.Since("zhttp.Template") l.FieldsSince().Print("") return x @@ -694,11 +701,19 @@ func (h backend) code(w http.ResponseWriter, r *http.Request) error { return err } + cd := cfg.DomainCount + if cd == "" { + cd = goatcounter.MustGetSite(r.Context()).Domain() + if cfg.Port != "" { + cd += ":" + cfg.Port + } + } + return zhttp.Template(w, "backend_code.gohtml", struct { Globals SubSites goatcounter.Sites CountDomain string - }{newGlobals(w, r), sites, cfg.DomainCount}) + }{newGlobals(w, r), sites, cd}) } func (h backend) ip(w http.ResponseWriter, r *http.Request) error { diff --git a/site.go b/site.go index 7cd347973..ae1fda18d 100644 --- a/site.go +++ b/site.go @@ -379,12 +379,12 @@ func (s Site) Domain() string { // URL to this site. func (s Site) URL() string { if s.Cname != nil { - return fmt.Sprintf("http%s://%s%s", + return fmt.Sprintf("http%s://%s:%s", map[bool]string{true: "s", false: ""}[cfg.Prod], *s.Cname, cfg.Port) } - return fmt.Sprintf("http%s://%s.%s%s", + return fmt.Sprintf("http%s://%s.%s:%s", map[bool]string{true: "s", false: ""}[cfg.Prod], s.Code, cfg.Domain, cfg.Port) }