tighten validation, add tests

This commit is contained in:
Alex committed 2026-05-11 10:12:27 -07:00
1 parent 272e4b5014
commit 08043a5ea0
7 files changed
+194 -109

No files matched your search

@@ -16,11 +16,19 @@ export class DNSProvider implements IStatusProvider<DNSStatusPayload> {
async handle(monitor: Monitor): Promise<MonitorStatusResponse<DNSStatusPayload>> {
try {
const { url: hostname, dnsServer, dnsRecordType = "A" } = monitor;
const { url, dnsServer, dnsRecordType = "A" } = monitor;
if (!dnsServer) {
throw new Error("DNS server is required for DNS monitoring");
}
let hostname: string;
try {
const withScheme = /^[a-z]+:\/\//i.test(url) ? url : `http://${url}`; // Ensure URL has a scheme for proper parsing
hostname = new URL(withScheme).hostname;
} catch {
hostname = url;
}
const resolver = this.createResolver();
resolver.setServers([dnsServer]);