feat: dynamically fetch live Cloudflare SSL TXT verification records in GET /domains endpoint

This commit is contained in:
AyrisAI
2026-08-20 17:35:23 +03:00
parent 8adec100af
commit 5103322fa1
+39 -1
View File
@@ -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",