/**
* Cron job to fetch and update WHOIS servers list
* Runs weekly to keep the WHOIS server list up-to-date
*/
import { writeFile } from "fs/promises";
import { join } from "path";
const WHOIS_SERVERS_URL = "https://whoislist.org/whois_servers.json";
const WHOIS_SERVERS_PATH = join(import.meta.dir, "../../whois-servers.json");
export async function updateWhoisServers(): Promise<void> {
try {
console.log(`[CRON] Fetching latest WHOIS servers from ${WHOIS_SERVERS_URL}...`);
const response = await fetch(WHOIS_SERVERS_URL, {
signal: AbortSignal.timeout(30000),
});
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
const data = await response.json() as Record<string, string>;
const tldCount = Object.keys(data).length;
// Write to file
await writeFile(
WHOIS_SERVERS_PATH,
JSON.stringify(data, null, 2),
"utf-8"
);
console.log(`[CRON] ✅ Successfully updated WHOIS servers list (${tldCount} TLDs)`);
console.log(`[CRON] File saved to: ${WHOIS_SERVERS_PATH}`);
} catch (error) {
console.error("[CRON] ❌ Failed to update WHOIS servers:", error);
throw error;
}
}
// Allow running directly for testing
if (import.meta.main) {
await updateWhoisServers();
}