Module supabase/functions/verify_custom_domain

Fileoverview

Verify Custom Domain Edge Function

Verifies DNS configuration for a custom domain and provisions the Caddy vhost if DNS verification succeeds.

Endpoint

POST /verify_custom_domain

Auth

Required - JWT verified by Supabase

Remarks

Verification process:

  1. Fetches domain record with container details
  2. Determines expected DNS value based on dns_method (A or CNAME)
  3. Queries Cloudflare DNS-over-HTTPS to verify record
  4. If DNS matches, calls Infrastructure Provisioner to add Caddy vhost
  5. Updates domain status to 'ready' or 'error'

DNS Methods:

  • a: Expects A record pointing to 46.224.1.156
  • cname: Expects CNAME record pointing to container's edge_hostname

Tables touched:

  • custom_domains (read/write)
  • sgtm_containers (read via join)

External services:

  • Cloudflare DNS-over-HTTPS (cloudflare-dns.com)
  • Infrastructure Provisioner (INFRA_PROVISIONER_URL) for Caddy setup

Example: Request body

{ "domain_id": "uuid" }

Returns

200 - Success with domain status (ready or error with details)

Returns

400 - Missing domain_id or container not configured

Returns

404 - Domain not found

Returns

500 - Server configuration error or infrastructure failure