Query Response Object Types

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. Objects can be returned as a single object or as an array of objects depending on the desired output.

Each response object usually consists of a constructor that receives a string representation of the value and a TTL value parameter that determine how long the response client should cache the object.

Supported response objects:

  • ARecord
  • AaaaRecord
  • CnameRecord
  • PullZoneRecords

Example response:

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.

/*
    Handle the DNS query!
 */
export default function handleQuery(query) {
    if(query.geoLocation.country == "DE") {
      return new ARecord("222.222.222.222", 30);
    }
  
    return new ARecord("111.111.111.111", 30);
}

ARecord

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;
}

AaaaRecord

The AaaaRecordrepresents 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;
}

Cname Record

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;
}

PullZoneRecord

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;
}

Did this page help you?