- test(ui): avoid a literal em dash in the em dash check - fix(cli): accept any positive int64 audit count and share the last active admin rule - fix(api): limit audit before_id to 2^53-1 - fix(api): audit unmatched api requests, bound every request body and record audit write failures - fix(ui): recheck the account in the login transaction and require existing zones on zone pages - fix(api): recheck the acting admin and the stored password hash in change transactions - fix(db): keep committed outcomes on lock release failure, narrow the records contract and trace sql statements - fix(db): make the initial migration restartable and verify the application schema - fix(auth): never move last_seen_at backwards on concurrent session touches - test(api): cover lock release failure after commit and handler tracing without secrets - fix(test): redact credentials from mysql setup errors - fix(audit): retain addressed objects on admin refusals - test(db): cover migration restarts and records contract ranges in mysql - test(api): verify account races and audit rollback in mysql - fix(auth): reject password changes after account deletion - docs: document unknown api audit entries - fix(audit): bound failure retries and redact sensitive sql parameters - fix(test): isolate docker resources and cover image cli commands - test(auth): expect unauthorized after an account deletion race - fix(db): verify application column widths and foreign keys
61 lines
1.7 KiB
Go
61 lines
1.7 KiB
Go
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
// Copyright (C) 2026 Bryan Joshua Pedini
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
|
)
|
|
|
|
type routeRegistrar func(s *WebServer, r *mux.Router)
|
|
|
|
type handlerMiddleware func(s *WebServer, next http.Handler) http.Handler
|
|
|
|
var appRouteRegistrars = []routeRegistrar{registerAppRoutes}
|
|
|
|
var appMiddlewares = []handlerMiddleware{requestLogMiddleware, securityHeadersMiddleware, crossOriginMiddleware}
|
|
|
|
func (s *WebServer) Handler() http.Handler {
|
|
r := mux.NewRouter()
|
|
r.SkipClean(true)
|
|
s.Routes(r)
|
|
h := cleanPagePath(r)
|
|
for i := len(appMiddlewares) - 1; i >= 0; i-- {
|
|
h = appMiddlewares[i](s, h)
|
|
}
|
|
return h
|
|
}
|
|
|
|
func (s *WebServer) Routes(r *mux.Router) {
|
|
r.HandleFunc("/health", s.handleHealth).Methods(http.MethodGet)
|
|
r.HandleFunc("/version", s.handleVersion).Methods(http.MethodGet)
|
|
for _, register := range appRouteRegistrars {
|
|
register(s, r)
|
|
}
|
|
}
|
|
|
|
const (
|
|
healthOK = `{"status":"ok"}`
|
|
healthUnavailable = `{"status":"unavailable"}`
|
|
)
|
|
|
|
func (s *WebServer) handleHealth(w http.ResponseWriter, r *http.Request) {
|
|
defer traceFunc(r.Context(), s.log, "page.health")()
|
|
status, body := http.StatusOK, healthOK
|
|
ctx, cancel := context.WithTimeout(r.Context(), healthPingTimeout)
|
|
defer cancel()
|
|
if s.pinger == nil {
|
|
status, body = http.StatusServiceUnavailable, healthUnavailable
|
|
} else if err := s.pinger.PingContext(ctx); err != nil {
|
|
s.log.ErrorContext(r.Context(), "health check ping failed", "error", err)
|
|
status, body = http.StatusServiceUnavailable, healthUnavailable
|
|
}
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.Header().Set("Cache-Control", "no-store")
|
|
w.WriteHeader(status)
|
|
_, _ = w.Write([]byte(body))
|
|
}
|