From 4fe2a9c91af93dad2b9da916736d65da4fb8e8d0 Mon Sep 17 00:00:00 2001 From: Leo Wandersleb Date: Sat, 17 Dec 2022 13:08:59 -0300 Subject: [PATCH] use default fetch if in service worker (#23) --- nip05.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/nip05.js b/nip05.js index c1dd8b0..368c5ae 100644 --- a/nip05.js +++ b/nip05.js @@ -1,9 +1,12 @@ -import fetch from 'cross-fetch' +import crossFetch from 'cross-fetch' +const f = (typeof XMLHttpRequest == 'function') + ? crossFetch + : fetch export async function searchDomain(domain, query = '') { try { let res = await ( - await fetch(`https://${domain}/.well-known/nostr.json?name=${query}`) + await f(`https://${domain}/.well-known/nostr.json?name=${query}`) ).json() return res.names @@ -18,11 +21,12 @@ export async function queryName(fullname) { if (!domain) return null let res = await ( - await fetch(`https://${domain}/.well-known/nostr.json?name=${name}`) + await f(`https://${domain}/.well-known/nostr.json?name=${name}`) ).json() return res.names && res.names[name] - } catch (_) { + } catch (e) { + console.error(`${e}`) return null } }