feat(statuspages): email subscriptions, RSS feed and a JSON API
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / test (pull_request) Successful in 9m5s
ci / lint (pull_request) Successful in 10m24s
ci / build (pull_request) Successful in 18m10s
ci / image (pull_request) Successful in 5m16s

Visitors can subscribe to a page's incidents by email where the
organization allows it. They confirm their address first; confirmation
and unsubscribe links only show a button, so mail scanners do not act on
them, and mails carry RFC 8058 one-click unsubscribe headers. Subscribers
get a mail when an incident opens or resolves and for every public
update.

Every page also has an RSS feed of incidents and planned maintenance and
a read-only JSON API (status, summary, components, incidents), both
served from the cached snapshot.

Abuse protection: status page servers limit feed and API reads,
subscription requests and link actions per visitor; the API limits
subscription requests per visitor, mailbox and page, and a new limit caps
the subscriptions an organization's pages gain in seven days (platform
default and per-organization override, 1000 in the cloud). Unconfirmed
subscriptions count towards it and are deleted after a week.

The fixed cap of 200 monitors per status page is gone; the configurable
limit alone decides.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-26 18:18:08 +01:00
1 parent df39b765cb
commit cca4e80e54
39 files changed
+4332 -1408

No files matched your search

+44 -41
View File
@@ -92,6 +92,7 @@ type Server struct {
// the current second.
unknownSecond int64
unknownCount int
limits limiters
// background tracks refreshes started by visits.
background sync.WaitGroup
}
@@ -124,7 +125,7 @@ func New(src Source, catalog *i18n.Catalog, log *slog.Logger, o Options) (*Serve
s := &Server{
src: src, catalog: catalog, log: log, ownHosts: map[string]bool{}, dir: o.CacheDir,
now: time.Now, cache: map[string]entry{}, refreshing: map[string]bool{}, again: map[string]bool{}, visited: map[string]time.Time{},
missing: map[string]time.Time{},
missing: map[string]time.Time{}, limits: newLimiters(),
}
for _, h := range o.Hosts {
s.ownHosts[strings.ToLower(h)] = true
@@ -226,53 +227,45 @@ func hostOnly(h string) string {
}
func (s *Server) serve(c *gin.Context) {
if c.Request.Method != http.MethodGet && c.Request.Method != http.MethodHead {
host := hostOnly(c.Request.Host)
var parts []string
if trimmed := strings.Trim(c.Request.URL.Path, "/"); trimmed != "" {
parts = strings.Split(trimmed, "/")
}
var key, slug, base string
if s.IsCustomDomain(host) {
key, base = "host:"+host, "/"
} else {
if len(parts) == 0 {
c.Status(http.StatusNotFound)
return
}
slug, parts = parts[0], parts[1:]
key, host, base = "slug:"+slug, "", "/"+slug+"/"
}
rt, ok := routeOf(parts)
if !ok {
c.Status(http.StatusNotFound)
return
}
switch m := c.Request.Method; {
case m == http.MethodPost && rt.kind.posts():
case m != http.MethodGet && m != http.MethodHead:
c.Status(http.StatusMethodNotAllowed)
return
}
host := hostOnly(c.Request.Host)
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, "/"
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 slug == "" {
c.Status(http.StatusNotFound)
return
}
key, host, base = "slug:"+slug, "", "/"+slug+"/"
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
}
if limit := s.limiterFor(rt.kind); limit != nil && !limit.allow(c.ClientIP(), s.now()) {
c.Header("Retry-After", "60")
c.Status(http.StatusTooManyRequests)
return
}
e, ok := s.lookup(c.Request.Context(), key, host, slug)
if !ok {
c.Status(http.StatusNotFound)
return
}
if legal != "" {
s.serveLegal(c, e, legal, base)
if rt.kind == routeLegal {
s.serveLegal(c, e, rt.arg, base)
return
}
var staleSince time.Time
@@ -286,8 +279,18 @@ func (s *Server) serve(c *gin.Context) {
ComponentBase: base,
Now: s.now(),
}
if compID != "" {
s.serveComponent(c, e, compID, assets)
switch rt.kind {
case routeComponent:
s.serveComponent(c, e, rt.arg, assets)
return
case routeFeed:
s.serveFeed(c, e, base)
return
case routeAPI:
s.serveAPI(c, e, rt.arg, base)
return
case routeSubscribe, routeConfirm, routeUnsubscribe:
s.serveSubscription(c, e, rt.kind, host, slug, base, assets)
return
}
s.localizeRequest(c)