Skip to content

Commit

Permalink
Set DomainCount for serve too
Browse files Browse the repository at this point in the history
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 😅
  • Loading branch information
arp242 committed Mar 27, 2020
1 parent 2eae1d1 commit bb053d3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
1 change: 1 addition & 0 deletions cmd/goatcounter/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func serve() (int, error) {
v.Domain("-domain", cfg.DomainStatic)
}
cfg.URLStatic = "//" + cfg.DomainStatic
cfg.DomainCount = cfg.DomainStatic
}

flagAuth(auth, &v)
Expand Down
27 changes: 21 additions & 6 deletions handlers/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions site.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit bb053d3

Please sign in to comment.