diff --git a/api/index.ts b/api/index.ts index dff86ea..eba7156 100644 --- a/api/index.ts +++ b/api/index.ts @@ -70,7 +70,7 @@ async function apiBuilder (cfg: APIConfig): Promise { const store = new Store(cfg, db, protocols) server.log.info('Initializing DNS server') - const dns = await initDnsServer(cfg.dnsport, store.sites, server.log) + const dns = await initDnsServer(cfg.dnsport, store.sites, server.log, cfg.host) server.log.info('Done') await registerAuth(cfg, server, store) diff --git a/dns/index.ts b/dns/index.ts index 480caa7..db7390a 100644 --- a/dns/index.ts +++ b/dns/index.ts @@ -4,7 +4,7 @@ import { SiteConfigStore } from '../config/sites.js' const TTL = 604800 // 7 days ttl -export async function initDnsServer (port: number, store: SiteConfigStore, logger?: FastifyBaseLogger): Promise> { +export async function initDnsServer (port: number, store: SiteConfigStore, logger?: FastifyBaseLogger, host?: string = 'api.distributed.press'): Promise> { const server = dns2.createServer({ udp: true, handle: (request, send, rinfo) => { @@ -12,6 +12,15 @@ export async function initDnsServer (port: number, store: SiteConfigStore, logge const [{ name }] = request.questions logger?.info(`[dns] ${rinfo.address}:${rinfo.port} asked for ${name}`) + // TODO: Pass server from config + response.authorities.push({ + name, + type: dns2.Packet.TYPE.NS, + class: dns2.Packet.CLASS.IN, + ttl: TTL, + ns: `${host}.` + }) + const cleanedName = name.toLowerCase().replace('_dnslink.', '') store.get(cleanedName) .then(({ links }) => { @@ -33,6 +42,7 @@ export async function initDnsServer (port: number, store: SiteConfigStore, logge data: `dnslink=${links.hyper.dnslink}` }) } + send(response) }) .catch((error) => {