coolify-deployment-cli
Version:
CLI tool for Coolify deployments
72 lines (61 loc) • 1.68 kB
JavaScript
const dns = require('dns').promises;
class DNSHelperCore {
constructor(options = {}) {
this.timeout = options.timeout || 5000;
this.retries = options.retries || 3;
}
async withTimeout(promise, timeoutMs = this.timeout) {
return Promise.race([
promise,
new Promise((_, reject) =>
setTimeout(() => reject(new Error('DNS timeout')), timeoutMs)
)
]);
}
async retryOperation(operation, retries = this.retries) {
for (let i = 0; i < retries; i++) {
try {
return await operation();
} catch (error) {
if (i === retries - 1) throw error;
await new Promise(resolve => setTimeout(resolve, 1000 * (i + 1)));
}
}
}
async checkDNSRecord(domain, recordType) {
try {
const result = await this.withTimeout(
this.retryOperation(() => dns.resolve(domain, recordType))
);
return {
type: recordType,
domain: domain,
records: result,
success: true,
error: null
};
} catch (error) {
return {
type: recordType,
domain: domain,
records: [],
success: false,
error: error.code === 'ENODATA' ? 'No records found' : error.message
};
}
}
async checkARecords(domain) {
return await this.checkDNSRecord(domain, 'A');
}
async checkAAAARecords(domain) {
return await this.checkDNSRecord(domain, 'AAAA');
}
async checkTXTRecords(domain) {
return await this.checkDNSRecord(domain, 'TXT');
}
async checkNSRecords(domain) {
return await this.checkDNSRecord(domain, 'NS');
}
}
module.exports = DNSHelperCore;