Files
Warp/apps/admin/cmd/warp-admin/main.go
T
tajniak81andClaude Opus 5.5 7e5e38c921 Admin panel (warp-admin) and the apps/ui design system
apps/ui: Warp's design system for Vue 3 + Tailwind v4. Tokens, fonts,
icons and logo come from the brand package, with a Tailwind theme on the
tokens and Vue components on the brand component styles.

apps/admin: the admin panel as a separate, optional service. warp-admin
embeds the built Vue app and proxies only the login endpoints and
/_warp/admin/v1 to the homeserver. Pages: dashboard, users, rooms,
federation, registration and tokens, server notices, application
services, audit log.

Also: pnpm workspace, go.work entry, Dockerfile, an `admin` compose
profile, Makefile targets, a CI job with a proxy smoke test, and docs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 15:05:16 +02:00

116 lines
2.8 KiB
Go

// Command warp-admin serves the Warp admin panel and proxies its requests
// to a homeserver. It is optional: a Warp server runs without it, and an
// operator who wants the panel runs this next to it.
//
// warp-admin -homeserver http://localhost:8008 -listen :8009
package main
import (
"context"
"errors"
"flag"
"fmt"
"log/slog"
"net/http"
"net/url"
"os"
"os/signal"
"strings"
"syscall"
"time"
"github.com/dariuszjaniak/warp/apps/admin/internal/host"
"github.com/dariuszjaniak/warp/apps/admin/internal/panel"
)
// Set with -ldflags "-X main.version=...".
var version = "0.0.0-dev"
func main() {
if err := run(); err != nil {
fmt.Fprintln(os.Stderr, "warp-admin:", err)
os.Exit(1)
}
}
func env(key, def string) string {
if v := os.Getenv(key); v != "" {
return v
}
return def
}
func run() error {
listen := flag.String("listen", env("WARP_ADMIN_LISTEN", ":8009"), "address to listen on (WARP_ADMIN_LISTEN)")
homeserver := flag.String("homeserver", env("WARP_ADMIN_HOMESERVER", "http://localhost:8008"),
"base URL of the Warp homeserver (WARP_ADMIN_HOMESERVER)")
logFormat := flag.String("log-format", env("WARP_ADMIN_LOG_FORMAT", "text"), "text or json (WARP_ADMIN_LOG_FORMAT)")
showVersion := flag.Bool("version", false, "print the version and exit")
flag.Parse()
if *showVersion {
fmt.Println("warp-admin", version)
return nil
}
var logger *slog.Logger
switch *logFormat {
case "json":
logger = slog.New(slog.NewJSONHandler(os.Stderr, nil))
case "text":
logger = slog.New(slog.NewTextHandler(os.Stderr, nil))
default:
return fmt.Errorf("unknown log format %q", *logFormat)
}
slog.SetDefault(logger)
target, err := url.Parse(strings.TrimRight(*homeserver, "/"))
if err != nil {
return fmt.Errorf("homeserver: %w", err)
}
files, built := panel.FS()
if !built {
logger.Warn("the panel was not built into this binary; serving a placeholder page")
files = nil
}
h, err := host.New(host.Options{Homeserver: target, Panel: files, Logger: logger})
if err != nil {
return err
}
srv := &http.Server{
Addr: *listen,
Handler: h,
ReadHeaderTimeout: 10 * time.Second,
ReadTimeout: time.Minute,
WriteTimeout: 3 * time.Minute,
IdleTimeout: 2 * time.Minute,
MaxHeaderBytes: 64 << 10,
}
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
errc := make(chan error, 1)
go func() {
logger.Info("warp-admin listening", "addr", *listen, "homeserver", target.String(), "version", version)
errc <- srv.ListenAndServe()
}()
select {
case err := <-errc:
if !errors.Is(err, http.ErrServerClosed) {
return err
}
return nil
case <-ctx.Done():
}
logger.Info("shutting down")
shutdownCtx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
return srv.Shutdown(shutdownCtx)
}