feat: dynamically fetch live Cloudflare SSL TXT verification records in GET /domains endpoint
This commit is contained in:
@@ -37,8 +37,46 @@ export const domainsRoutes: FastifyPluginAsync = async (app) => {
|
|||||||
|
|
||||||
const cnameTarget = `cname.${env.ROOT_DOMAIN}`;
|
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({
|
return reply.send({
|
||||||
domains: domains || [],
|
domains: enrichedDomains,
|
||||||
cnameTarget,
|
cnameTarget,
|
||||||
instructions: {
|
instructions: {
|
||||||
type: "CNAME",
|
type: "CNAME",
|
||||||
|
|||||||
Reference in New Issue
Block a user