mirror of
https://github.com/Qortal/qortal-ui.git
synced 2025-02-11 17:55:51 +00:00
32 lines
630 B
JavaScript
32 lines
630 B
JavaScript
import { waitForConfig, watchConfig } from '../config'
|
|
|
|
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 {
|
|
return await response.clone().json()
|
|
} catch (e) {
|
|
return await response.text()
|
|
}
|
|
})
|
|
}
|