Sign inSign up

zackwag/caddy-ui-backend

By zackwag

Updated 3 days ago

API backend for caddy/ui — manages Caddy config, health checks, TLS, logs, and notifications

Image
Networking
Developer tools
0

10K+

zackwag/caddy-ui-backend repository overview

caddy/ui — Backend

The API backend for caddy/ui, a web interface for managing your Caddy server. Built with Node.js and Express.

This is the backend image. You will also need the frontend image.

Features

  • Proxies requests to Caddy's admin API (/config, /id, /load)
  • Reads and writes the Caddyfile on disk
  • Runs caddy validate via Caddy's /adapt admin API endpoint
  • Runs caddy fmt and detects Caddy version via docker exec into the running Caddy container (requires Docker socket mount)
  • Sorts Caddyfile site blocks on save (public → internal → http)
  • Appends, updates, and removes site blocks when routes are managed via the UI
  • Fetches routes from all server blocks with recursive upstream extraction for complex route structures
  • Health checks use Caddy's reverse proxy upstream pool API as primary source, with TCP fallback for upstreams not yet in the pool
  • In-memory rolling uptime tracking per upstream (288-check window, ~2.5 hours)
  • Push notifications via ntfy, Discord, Slack, Pushover, or custom webhook — triggered on upstream offline/online and cert expiry
  • Configurable notification debounce to suppress repeat alerts
  • Reads TLS certificate files from disk and parses expiry dates
  • Detects and deletes orphaned, superseded, and expired certificates (resolves issuer directory automatically)
  • Root CA cert download via Caddy's /pki/ca/local admin API
  • Automatic Caddyfile snapshots on every save with configurable retention
  • Tails and streams access logs via SSE
  • Parses and updates log configuration in the global Caddyfile block
  • Persists server block display names and route notes to disk
  • Optional JWT authentication protecting all API endpoints
  • Caddy process info and HTTP metrics via Prometheus endpoint
  • Metrics enable/disable toggle that modifies the Caddyfile global block
  • Optional public /api/metrics/raw endpoint for Prometheus scraping
  • Structured JSON logging with configurable log level via LOG_LEVEL
  • Enriched status endpoint with route count, upstream health, and uptime for Homepage widget support

Quick Start

services:
  caddy-ui-backend:
    image: zackwag/caddy-ui-backend:latest
    container_name: caddy-ui-backend
    restart: unless-stopped
    ports:
      - 9876:3001
    environment:
      - TZ=America/New_York
      # Optional auth -- leave unset to disable
      - CADDY_UI_USER=admin
      - CADDY_UI_PASSWORD=yourpassword
      - JWT_SECRET=your-long-random-secret
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /docker/caddy/Caddyfile:/etc/caddy/Caddyfile
      - /docker/caddy/logs:/var/log/caddy
      - /docker/caddy-ui:/etc/caddy-ui
      - /docker/caddy/data:/data/caddy
    networks:
      - caddy-ui
    depends_on:
      - caddy

Note: The Docker socket mount is required for caddy fmt formatting and Caddy version detection. The backend runs docker exec into the Caddy container — make sure CADDY_CONTAINER_NAME matches your Caddy container name if it differs from caddy.

Environment Variables

All variables have sensible defaults. Only set what you need to override.

VariableDefaultDescription
CADDY_ADMIN_URLhttp://caddy:2019URL of Caddy's admin API
CADDY_CONFIG_PATH/etc/caddy/CaddyfilePath to the Caddyfile inside the container
CADDY_CONTAINER_NAMEcaddyName of the Caddy container (used for docker exec)
CADDY_DATA_PATH/data/caddy/caddyPath to Caddy's data directory containing certificates
CADDY_LOG_PATH/var/log/caddy/access.logPath to Caddy's access log
CADDY_SERVER_NAMEsrv0Primary server block name for new routes
CADDY_UI_PASSWORDPassword for UI authentication
CADDY_UI_PUBLIC_METRICSfalseExpose /api/metrics/raw without auth for Prometheus scraping
CADDY_UI_USERUsername for UI authentication (leave unset to disable auth)
HISTORY_PATH/etc/caddy-ui/historyPath to the Caddyfile snapshot directory
JWT_SECRETSecret key for signing JWT tokens
LOG_LEVELinfoLog verbosity (debug, info, warn, error)
NOTIFICATIONS_CONFIG_PATH/etc/caddy-ui/notifications.jsonPath to the notification settings file
PORT3001Port the backend listens on
ROUTE_NOTES_PATH/etc/caddy-ui/route-notes.jsonPath to the route notes file
SERVER_NAMES_PATH/etc/caddy-ui/server-names.jsonPath to the server display names file

Authentication

Authentication is disabled by default. Set CADDY_UI_USER, CADDY_UI_PASSWORD, and JWT_SECRET to enable it. All /api/* endpoints are protected and the login screen appears automatically.

Generate a secure JWT secret:

openssl rand -base64 32

Prometheus Metrics

If CADDY_UI_PUBLIC_METRICS=true, the endpoint GET /api/metrics/raw is available without authentication. Example Prometheus scrape config:

scrape_configs:
  - job_name: caddy
    static_configs:
      - targets: ['caddy-ui-backend:3001']
    metrics_path: /api/metrics/raw

Caddy's metrics endpoint must be enabled in your Caddyfile global block:

{
    email [email protected]
    metrics
}

This can be toggled from the caddy/ui Metrics tab without editing the Caddyfile manually.

Homepage Widget

The status endpoint returns enriched data for use with Homepage:

- Caddy:
    href: https://caddy.home
    icon: caddy.png
    widget:
      type: customapi
      url: http://caddy-ui-backend:3001/api/status
      mappings:
        - field: online
          label: Status
          format: text
          remap:
            - value: true
              to: Online
            - value: false
              to: Offline
        - field: routeCount
          label: Routes
          format: number
        - field: upstreamsOnline
          label: Upstreams
          format: number
        - field: uptime
          label: Uptime
          format: text

Required Volumes

Host PathContainer PathPurpose
/var/run/docker.sock/var/run/docker.sockDocker socket for caddy fmt and version detection
/docker/caddy/Caddyfile/etc/caddy/CaddyfileShared Caddyfile with the Caddy container
/docker/caddy/logs/var/log/caddyShared log directory with the Caddy container
/docker/caddy-ui/etc/caddy-uiPersistent storage for server names, notes, history, and notification config
/docker/caddy/data/data/caddyCaddy data directory for TLS certificate access

API Endpoints

MethodEndpointDescription
POST/api/auth/sessionsAuthenticate and receive a JWT token
GET/api/auth/statusCheck if auth is enabled
GET/api/metricsParsed HTTP metrics for the Metrics tab
GET/api/metrics/configCheck if Caddy metrics directive is enabled
PUT/api/metrics/configEnable or disable Caddy metrics directive
GET/api/metrics/rawRaw Prometheus metrics (public if CADDY_UI_PUBLIC_METRICS=true)
GET/api/statusServer status, route count, upstream health, and uptime
GET/api/status/caddy-configFull raw Caddy JSON config
GET/api/status/processCaddy process info including version
GET/api/caddyfileRead Caddyfile from disk
GET/api/caddyfile?download=trueDownload Caddyfile as a timestamped attachment
PUT/api/caddyfileSave, validate, format, and reload
POST/api/caddyfile/validationsValidate (and optionally format) without saving
POST/api/caddyfile/reloadsReload Caddy from disk
GET/api/caddyfile/historyList all Caddyfile snapshots
GET/api/caddyfile/history/:filenameRead a specific snapshot
DELETE/api/caddyfile/history/:filenameDelete a snapshot
GET/api/routesList all routes across all server blocks
POST/api/routesAdd a reverse proxy route
PATCH/api/routes/:idUpdate a UI-managed route by ID
DELETE/api/routes/:idRemove a route and its Caddyfile block
GET/api/route-notesRead all route notes
PUT/api/route-notes/:domainSet or clear a route note
GET/api/healthCheck upstream health via Caddy pool API with TCP fallback
GET/api/health/uptimeUptime stats per upstream from rolling history
GET/api/tlsList all certificates with expiry and status
DELETE/api/tls/:domainDelete an orphaned, superseded, or expired internal cert
GET/api/tls/caDownload Caddy's root CA certificate
GET/api/logsLast 200 lines of the access log
GET/api/logs/streamSSE stream of live log output
GET/api/logs/configRead log configuration
PUT/api/logs/configUpdate log configuration
GET/api/server-namesRead server block display names
PUT/api/server-names/:idSet a display name
DELETE/api/server-names/:idClear a display name
GET/api/notifications/configRead notification settings
PUT/api/notifications/configUpdate notification settings
POST/api/notifications/testSend a test notification

Tags

TagDescription
latestMost recent stable build
v1.12Push notifications, release workflow
v1.11Caddy binary bundled, upstream pool health checks, PKI API
v1.10.1Caddy /adapt API validation, Docker socket removal
v1.10React Router, RESTful API audit, Homepage widget
v1.9Dark/light theme, log export, root CA download
v1.8Metrics tab, uptime tracking
v1.7JWT auth, Caddy process info, metrics toggle
v1.6Edit routes, route notes, Caddyfile sync
v1.5Caddyfile version history, automatic snapshots
v1.4Caddyfile backup/restore, dashboard health summary
v1.3Upstream healthchecks, scheme detection
v1.2TLS certificate management, orphaned cert cleanup
v1.1Initial release

Source

github.com/zackwag/caddy-ui

Tag summary

Content type

Image

Digest

sha256:d609c8eec

Size

58 MB

Last updated

3 days ago

docker pull zackwag/caddy-ui-backend