All checks were successful
check / check (push) Successful in 45s
Remove CDN dependency (cdn.tailwindcss.com) and replace with a pre-built, minified Tailwind CSS file embedded in the Go binary via go:embed. Changes: - Add static/static.go with go:embed for css/ directory - Add static/css/tailwind.min.css (9KB, contains only classes used by the dashboard template) - Remove <script src="https://cdn.tailwindcss.com"> and inline tailwind.config from dashboard.html - Replace with <link rel="stylesheet" href="/s/css/tailwind.min.css"> - Mount /s/ route for embedded static file serving (go-chi) - Add /.well-known/healthcheck endpoint per GO_HTTP_SERVER conventions Zero external HTTP requests from the browser. All assets served from the binary itself. Closes #82
65 lines
1.4 KiB
Go
65 lines
1.4 KiB
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
chimw "github.com/go-chi/chi/v5/middleware"
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
|
|
"sneak.berlin/go/dnswatcher/static"
|
|
)
|
|
|
|
// requestTimeout is the maximum duration for handling a request.
|
|
const requestTimeout = 60 * time.Second
|
|
|
|
// SetupRoutes configures all HTTP routes.
|
|
func (s *Server) SetupRoutes() {
|
|
s.router = chi.NewRouter()
|
|
|
|
// Global middleware
|
|
s.router.Use(chimw.Recoverer)
|
|
s.router.Use(chimw.RequestID)
|
|
s.router.Use(s.mw.Logging())
|
|
s.router.Use(s.mw.CORS())
|
|
s.router.Use(chimw.Timeout(requestTimeout))
|
|
|
|
// Dashboard (read-only web UI)
|
|
s.router.Get("/", s.handlers.HandleDashboard())
|
|
|
|
// Static assets (embedded CSS/JS)
|
|
s.router.Mount(
|
|
"/s",
|
|
http.StripPrefix(
|
|
"/s",
|
|
http.FileServer(http.FS(static.Static)),
|
|
),
|
|
)
|
|
|
|
// Health check (standard well-known path)
|
|
s.router.Get(
|
|
"/.well-known/healthcheck",
|
|
s.handlers.HandleHealthCheck(),
|
|
)
|
|
|
|
// Legacy health check (keep for backward compatibility)
|
|
s.router.Get("/health", s.handlers.HandleHealthCheck())
|
|
|
|
// API v1 routes
|
|
s.router.Route("/api/v1", func(r chi.Router) {
|
|
r.Get("/status", s.handlers.HandleStatus())
|
|
})
|
|
|
|
// Metrics endpoint (optional, with basic auth)
|
|
if s.params.Config.MetricsUsername != "" {
|
|
s.router.Group(func(r chi.Router) {
|
|
r.Use(s.mw.MetricsAuth())
|
|
r.Get(
|
|
"/metrics",
|
|
promhttp.Handler().ServeHTTP,
|
|
)
|
|
})
|
|
}
|
|
}
|