qortal-ui/crypto/api/fetch-request.js

30 lines
629 B
JavaScript
Raw Normal View History

2023-11-05 14:30:07 +01:00
import {waitForConfig, watchConfig} from '../config.js'
2021-12-25 14:39:47 +01:00
let config = {}
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
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()
}
})
}