feat(statuspage): add nested status page groups and optional component details
This commit is contained in:
1 parent
1c31003baf
commit
9b26b4150e
26 files changed
+4566
-760
No files matched your search
@@ -192,29 +192,40 @@ func (s *Server) serve(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
host := hostOnly(c.Request.Host)
|
||||
parts := strings.Split(strings.Trim(c.Request.URL.Path, "/"), "/")
|
||||
var key, slug, base, legal string
|
||||
trimmed := strings.Trim(c.Request.URL.Path, "/")
|
||||
parts := strings.Split(trimmed, "/")
|
||||
var key, slug, base, legal, compID string
|
||||
custom := s.IsCustomDomain(host)
|
||||
switch {
|
||||
case custom:
|
||||
key, base = "host:"+host, "/"
|
||||
if len(parts) > 1 {
|
||||
switch {
|
||||
case trimmed == "":
|
||||
case len(parts) == 1:
|
||||
legal = parts[0]
|
||||
case len(parts) == 2 && parts[0] == "components" && parts[1] != "":
|
||||
compID = parts[1]
|
||||
default:
|
||||
c.Status(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
default:
|
||||
slug = parts[0]
|
||||
if len(parts) == 2 {
|
||||
legal = parts[1]
|
||||
}
|
||||
if slug == "" || len(parts) > 2 {
|
||||
if slug == "" {
|
||||
c.Status(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
key, host, base = "slug:"+slug, "", "/"+slug+"/"
|
||||
}
|
||||
if custom {
|
||||
legal = parts[0]
|
||||
switch {
|
||||
case len(parts) == 1:
|
||||
case len(parts) == 2:
|
||||
legal = parts[1]
|
||||
case len(parts) == 3 && parts[1] == "components" && parts[2] != "":
|
||||
compID = parts[2]
|
||||
default:
|
||||
c.Status(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
}
|
||||
e, ok := s.lookup(c.Request.Context(), key, host, slug)
|
||||
if !ok {
|
||||
@@ -229,9 +240,38 @@ func (s *Server) serve(c *gin.Context) {
|
||||
if s.now().Sub(e.Fetched) > staleNoticeAfter {
|
||||
staleSince = e.Fetched
|
||||
}
|
||||
assets := web.PublicAssets{
|
||||
CSSHref: "/static/dist/app.css",
|
||||
StaleSince: staleSince,
|
||||
LegalBase: base,
|
||||
ComponentBase: base,
|
||||
Now: s.now(),
|
||||
}
|
||||
if compID != "" {
|
||||
s.serveComponent(c, e, compID, assets)
|
||||
return
|
||||
}
|
||||
s.localizeRequest(c)
|
||||
c.Header("Cache-Control", "public, max-age=30")
|
||||
web.Render(c, http.StatusOK, web.PublicStatusPage(e.Snap.WithMaintenance(s.now()), web.PublicAssets{CSSHref: "/static/dist/app.css", StaleSince: staleSince, LegalBase: base, Now: s.now()}))
|
||||
web.Render(c, http.StatusOK, web.PublicStatusPage(e.Snap.WithMaintenance(s.now()), assets))
|
||||
}
|
||||
|
||||
// serveComponent renders one component's public detail page from the cached
|
||||
// snapshot when the status page has enabled ShowDetails.
|
||||
func (s *Server) serveComponent(c *gin.Context, e entry, compID string, assets web.PublicAssets) {
|
||||
snap := e.Snap.WithMaintenance(assets.Now)
|
||||
if !snap.ShowDetails {
|
||||
c.Status(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
comp, ok := snap.ComponentByID(compID)
|
||||
if !ok {
|
||||
c.Status(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
s.localizeRequest(c)
|
||||
c.Header("Cache-Control", "public, max-age=30")
|
||||
web.Render(c, http.StatusOK, web.PublicComponentPage(snap, comp, assets))
|
||||
}
|
||||
|
||||
// serveLegal shows a legal document of the page from the cached snapshot,
|
||||
|
||||
Reference in new issue
Block a user