From b9645a63151b39d029644e457d4c8e90039eb140 Mon Sep 17 00:00:00 2001 From: Ben Visness Date: Fri, 30 Jul 2021 22:31:43 -0500 Subject: [PATCH] Extract the project slug more betterly --- src/hmnurl/hmnurl.go | 4 ++++ src/website/routes.go | 7 ++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/hmnurl/hmnurl.go b/src/hmnurl/hmnurl.go index a7479c40..134aebe2 100644 --- a/src/hmnurl/hmnurl.go +++ b/src/hmnurl/hmnurl.go @@ -56,6 +56,10 @@ func SetS3BaseUrl(base string) { S3BaseUrl = base } +func GetBaseHost() string { + return baseUrlParsed.Host +} + func Url(path string, query []Q) string { return ProjectUrl(path, query, "") } diff --git a/src/website/routes.go b/src/website/routes.go index c242928e..cede2ef2 100644 --- a/src/website/routes.go +++ b/src/website/routes.go @@ -361,11 +361,8 @@ func LoadCommonWebsiteData(c *RequestContext) (bool, ResponseData) { // get project { - slug := "" - hostParts := strings.SplitN(c.Req.Host, ".", 3) - if len(hostParts) >= 3 { - slug = hostParts[0] - } + hostPrefix := strings.TrimSuffix(c.Req.Host, hmnurl.GetBaseHost()) + slug := strings.TrimRight(hostPrefix, ".") dbProject, err := FetchProjectBySlug(c.Context(), c.Conn, slug) if err != nil {