use default fetch if in service worker (#23)

This commit is contained in:
Leo Wandersleb
2022-12-17 13:08:59 -03:00
committed by GitHub
parent e62b833464
commit 4fe2a9c91a

View File

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