The handleQuery entry point function supports multiple object return types to return different types of answers. This page contains the various types of answers the function can return to respond to queries.
Each response object usually consists of a constructor that receives a string representation of the value and a TTL value parameter that determines how long the response client should cache the object.Objects can be returned as a single object or as an array of objects depending on the desired output.
Below is an example code snippet to illustrate how to return a dynamic DNS response to a DNS query. If the request is coming from Germany, then 222.222.222.222 is returned, otherwise, 111.111.111.111 is returned.
export default function handleQuery(query) { if (query.request.geoLocation.country == "DE") { return new ARecord("222.222.222.222", 30); } return new ARecord("111.111.111.111", 30);}
The ARecord represents the A type DNS answer to return A records.
declare class ARecord { constructor(ip: string, ttl: number = 30); /** * The IP of the A record */ ip: string; /** * The TTL of the answer */ ttl: number;}
The AaaaRecord represents the AAAA type DNS answer to return AAAA records.
declare class AaaaRecord { constructor(ip: string, ttl: number = 30); /** * The IP of the AAAA record */ ip: string; /** * The TTL of the answer */ ttl: number;}
The CnameRecord represents the CNAME type DNS answer to return CNAME records.
declare class CnameRecord { constructor(hostname: string, ttl: number = 30); /** * The hostname of the CNAME record */ hostname: string; /** * The TTL of the answer */ ttl: number;}
The PullZoneRecord is used to map the response to a Pull Zone response, meaning the DNS system will automatically map the response to the appropriate A or AAAA records for this specific pull zone.
declare class PullZoneRecord { constructor(pullzone: string); /** * The name of the pull zone */ pullzone: string;}