Skip to content

Custom Domain Lifecycle & DCV Mechanics

How Shaf routes multi-tenant custom domains, automates Cloudflare for SaaS Domain Control Validation, and manages TLS certificates.

Custom Domain Lifecycle & DCV Mechanics

Operating branded short domains across thousands of organizations requires zero-downtime DNS routing, automated TLS certificate provisioning, tenant data isolation, and continuous certificate renewal.

Shaf automates this lifecycle using Cloudflare for SaaS (Custom Hostnames) and Anycast fallback routing.


The Host Routing Classification Matrix

Shaf’s edge middleware classifies every incoming HTTP request based on the incoming Host header before any database operations occur:

flowchart TD
    Req["Incoming HTTP Request"] --> Router{"Edge Host Router\n(Classification)"}

    Router -->|"shaf.app"| Mktg["Marketing & Documentation Host\n- Marketing static site\n- Nimbus documentation (/docs)\n- Public web tools"]

    Router -->|"dash.shaf.app"| Dash["Console Host\n- Nuxt 4 Single Page Application\n- Better Auth & RBAC\n- Billing & Settings"]

    Router -->|"shaf.is"| SysShort["System Short Domain\n- Core short link resolver\n- Unmapped root redirects to shaf.app"]

    Router -->|"link.brand.com"| TenantHost["Tenant Custom Domain\n- Scoped exclusively to owning org\n- Custom root & 404 redirects\n- Cloudflare for SaaS edge SSL"]

Each path is isolated at the edge. A request reaching link.brand.com can only resolve links belonging to the workspace that verified that domain. Cross-tenant link leakage is structurally impossible.


Domain Control Validation (DCV) Lifecycle

When an organization registers a custom domain, Cloudflare initiates automated Domain Control Validation (DCV) to issue an edge SSL/TLS certificate via Let’s Encrypt or Google Trust Services.

stateDiagram-v2
    [*] --> Initialized: POST /api/v1/domains
    Initialized --> PendingValidation: Cloudflare Hostname Created
    PendingValidation --> CertificateIssuance: CNAME / TXT Records Detected
    PendingValidation --> ValidationTimeout: DCV Check Times Out (72h)
    ValidationTimeout --> PendingValidation: Re-verify DNS Records
    CertificateIssuance --> Active: Edge TLS Certificate Deployed
    Active --> AutoRenewal: 30 Days Before Expiration
    AutoRenewal --> Active: TLS Certificate Extended
    Active --> Deleting: DELETE /api/v1/domains/:id
    Deleting --> [*]: TLS Revoked & KV Purged

DCV Verification Methods

Shaf supports two independent DNS verification mechanisms:

1. Direct CNAME Delegation

Recommended for dedicated short link subdomains (e.g. link.brand.com, go.acme.org).

  • Record Type: CNAME
  • Host / Name: link.brand.com
  • Target Value: cname.shaf.app Cloudflare validates hostname ownership and issues the TLS certificate automatically as soon as the CNAME record resolves globally.

2. Pre-Validation via TXT Records

Required when configuring apex domains (brand.com) or when migrating active production subdomains without downtime.

  • Verification Name: _cf-custom-hostname.link.brand.com
  • Verification Value: Unique UUID token generated during registration Allows certificate issuance before switching live CNAME traffic, ensuring 0 seconds of SSL downtime.

Cloudflare for SaaS Fallback Origin Architecture

Shaf maintains an Anycast fallback origin at cname.shaf.app:

  1. Global Traffic Absorption: Thousands of tenant hostnames point to the same Anycast target (cname.shaf.app).
  2. Edge Certificate Mapping: When a visitor connects via HTTPS to link.brand.com, Cloudflare’s edge matches the SNI to the tenant’s custom hostname and serves the tenant’s dedicated edge certificate.
  3. Internal Routing Metadata: The edge Worker inspects request.headers.get('Host') to look up the organization ID, fallback root redirect, and 404 URL in Workers KV in under 2 milliseconds.

Automated TLS Certificate Auto-Renewal

Custom hostname TLS certificates are valid for 90 days. Cloudflare initiates automated renewal 30 days prior to expiration:

  • As long as the customer’s DNS CNAME record remains pointed to cname.shaf.app, renewal succeeds with zero user action.
  • If DNS is altered or removed, Shaf alerts organization admins via email and webhook (domain.error) 14 days before certificate expiration.

Type to search…

↑↓ navigate↵ selectEsc close