kernel-libresolver/dist/index.js

38 lines
1004 B
JavaScript
Raw Normal View History

2022-08-18 22:00:26 +00:00
import { addHandler, handleMessage } from "libkmodule";
import { register } from "@lumeweb/kernel-dns-client";
let resolver;
export function setup(rm) {
addHandler("resolve", handleResolve);
addHandler("register", handleRegister);
2022-08-19 15:21:13 +00:00
addHandler("getSupportedTlds", handleGetSupportedTlds);
2022-08-18 22:00:26 +00:00
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);
}
2022-08-19 15:21:13 +00:00
function handleGetSupportedTlds(aq) {
aq.respond(resolver.getSupportedTlds());
}
2022-08-18 22:28:56 +00:00
export * from "./resolverRegistry.js";