4
1
mirror of https://github.com/Qortal/qortal-ui.git synced 2025-02-11 17:55:51 +00:00
qortal-ui/crypto/api/fetch-request.js

32 lines
630 B
JavaScript
Raw Permalink Normal View History

import { waitForConfig, watchConfig } from '../config'
2021-12-25 14:39:47 +01:00
let config = {}
2021-12-25 14:39:47 +01:00
watchConfig((c) => {
config = c
})
export async function request(url, options) {
options = options || {}
const body = options.body
const method = options.method || 'GET'
const headers = options.headers || {}
await waitForConfig()
const n = config.nodeConfig.knownNodes[config.nodeConfig.node]
const node = n.protocol + '://' + n.domain + ':' + n.port
2021-12-25 14:39:47 +01:00
return fetch(node + url, {
method,
headers,
body,
}).then(async (response) => {
try {
2024-03-29 09:00:10 +01:00
return await response.clone().json()
2021-12-25 14:39:47 +01:00
} catch (e) {
return await response.text()
}
})
}