Caddy is a modern web server that handles HTTPS provisioning and certificate renewals automatically.

Generate a Caddyfile

npx @docmd/core deploy --caddy

This generates a Caddyfile personalised to your project:

  • Site address is set to the hostname from your url config. Caddy automatically provisions an SSL certificate for it. It falls back to :80 if no URL is configured.
  • Root directory uses your configured out directory (not hardcoded).
  • SPA fallback is only included when layout.spa is true in your config.

What Gets Generated

docs.example.com {
    root * ./site
    file_server

    # SPA Routing Fallback (only when layout.spa is true)
    try_files {path} {path}/ /index.html

    # Security Headers
    header {
        X-Content-Type-Options "nosniff"
        X-Frame-Options "SAMEORIGIN"
        -Server
    }

    # Custom 404
    handle_errors {
        rewrite * /404.html
        file_server
    }

    # Cache Static Assets (6 months)
    @static {
        file
        path *.ico *.css *.js *.gif *.jpg *.jpeg *.png *.webp *.avif *.svg *.woff *.woff2 *.eot *.ttf *.otf
    }
    header @static Cache-Control "public, max-age=15552000, immutable"
}

When you use a real domain as the site address (e.g., docs.example.com instead of :80), Caddy automatically provisions a free SSL certificate via Let’s Encrypt. Zero HTTPS configuration is needed.

Deployment Steps

  1. Build your site: npx @docmd/core build
  2. Transfer your output folder and the generated Caddyfile to your server.
  3. Run caddy start or caddy run in the directory containing your Caddyfile.

Re-Generating

Changed your site URL or output directory? Run npx @docmd/core deploy --caddy again. The engine regenerates the Caddyfile to match your current docmd.config.json.