*Add dist

This commit is contained in:
Derrick Hammer 2022-08-18 18:00:26 -04:00
parent 183199247d
commit 1fe0496312
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 34 additions and 0 deletions

2
dist/index.d.ts vendored Normal file
View File

@ -0,0 +1,2 @@
import type { ResolverModule } from "@lumeweb/resolver-common";
export declare function setup(rm: ResolverModule): void;

32
dist/index.js vendored Normal file
View File

@ -0,0 +1,32 @@
import { addHandler, handleMessage } from "libkmodule";
import { register } from "@lumeweb/kernel-dns-client";
let resolver;
export function setup(rm) {
addHandler("resolve", handleResolve);
addHandler("register", handleRegister);
onmessage = handleMessage;
resolver = rm;
}
async function handleRegister(aq) {
await register();
aq.respond();
}
async function handleResolve(aq) {
if (!("domain" in aq.callerInput)) {
aq.reject("domain required");
return;
}
let ret;
try {
ret = await resolver.resolve(aq.callerInput.domain, aq.callerInput?.options ?? {}, aq.callerInput?.bypassCache || false);
}
catch (e) {
aq.reject(e);
return;
}
if (ret.error) {
aq.reject(ret.error);
return;
}
aq.respond(ret);
}