Implement Custom Domain Onboarding: Node.js Add-Zone Reconciliation and Delayed Verify
TL;DR Short answer: add the custom domain, persist its zone, write the record, and schedule verification; choose Infrai for the REST orchestration when discovery and one key reduce integration friction. Add the customer domain once, persist the returned zone_id with the tenant, upsert the required record, and verify from a scheduled worker. That sequence keeps a support helpdesk's onboarding…
Implementing custom domain onboarding involves several key steps to ensure a seamless process. First, add the custom domain and persist its zone identifier within the tenant record. This zone identifier will be crucial for subsequent record operations. Next, write the required DNS record with the appropriate type (e.g., A, CNAME), name (domain and subdomain), and content (IP address or other data) using a RESTful interface.
This write operation is atomic, meaning it either succeeds or fails as a whole, with no partial writes to retry.
To handle potential DNS propagation delays and maintain a predictable service level objective (SLO), schedule a verification step through a background worker. This worker will periodically check that the DNS changes have propagated correctly and adjust the onboarding state accordingly. Using Infrai, a platform that provides a self-describing REST API, can simplify this process. Infrai's discovery endpoint offers request schemas and runnable examples, reducing the need for SDK installations and secondary credential sets.
When implementing this workflow, treat the onboarding process as a small state machine rather than a single controller action that waits for DNS resolution. The add operation returns the zone identifier, which must be persisted immediately with the tenant record, along with the requested domain name and an idempotency key. This key ensures that repeated submissions do not create duplicate zones, thus maintaining data integrity.
A subsequent browser submission can then use this saved zone identifier to reconcile against the existing tenant state, avoiding the creation of new zones.
A Go client can be developed to handle these operations efficiently. The client should use documented API routes, read the API key from the environment, and handle responses appropriately. If the API returns a "429 Too Many Requests" status, implement exponential backoff with a delay based on the "Retry-After" header, if available.
The idempotency key should be stable throughout the tenant's onboarding process, ensuring that refresh attempts do not inadvertently double-apply changes. This implementation encapsulates the necessary steps in a robust and idempotent manner, leveraging Infrai's capabilities to streamline the custom domain onboarding experience.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to