From 5103322fa16440d3547dc93e84d4f220e2d53b48 Mon Sep 17 00:00:00 2001 From: AyrisAI Date: Thu, 20 Aug 2026 17:35:23 +0300 Subject: [PATCH] feat: dynamically fetch live Cloudflare SSL TXT verification records in GET /domains endpoint --- apps/api/src/routes/domains.ts | 40 +++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/apps/api/src/routes/domains.ts b/apps/api/src/routes/domains.ts index 8a271a2..40b5afe 100644 --- a/apps/api/src/routes/domains.ts +++ b/apps/api/src/routes/domains.ts @@ -37,8 +37,46 @@ export const domainsRoutes: FastifyPluginAsync = async (app) => { const cnameTarget = `cname.${env.ROOT_DOMAIN}`; + const enrichedDomains = await Promise.all( + (domains || []).map(async (domain) => { + if (domain.status === "verified") return domain; + + try { + const cfHostname = await getCustomHostnameByHostname(domain.hostname); + if (cfHostname) { + const ownershipTxt = cfHostname.ownership_verification + ? { name: cfHostname.ownership_verification.name, value: cfHostname.ownership_verification.value } + : null; + const sslTxt = (cfHostname.ssl?.validation_records ?? []).map((r) => ({ + name: r.txt_name, + value: r.txt_value, + })); + + return { + ...domain, + instructions: { + cname: { type: "CNAME", host: domain.hostname, target: cnameTarget }, + ownershipTxt, + sslTxt, + }, + cloudflareStatus: { + hostnameStatus: cfHostname.status, + sslStatus: cfHostname.ssl?.status, + ownershipTxt, + sslTxt, + }, + }; + } + } catch (err) { + req.log.warn({ err, hostname: domain.hostname }, "Cloudflare check failed during GET domains"); + } + + return domain; + }), + ); + return reply.send({ - domains: domains || [], + domains: enrichedDomains, cnameTarget, instructions: { type: "CNAME",