38 lines
860 B
JavaScript
38 lines
860 B
JavaScript
function combineUrl(url) {
|
|
if (typeof consts === 'undefined') {
|
|
return url;
|
|
}
|
|
return (consts.path || '') + url;
|
|
}
|
|
|
|
function get(url, options) {
|
|
options ??= {};
|
|
return fetch(combineUrl(url), {
|
|
method: options.method || 'GET',
|
|
headers: {
|
|
...options.customerHeaders,
|
|
'Content-Type': options.contentType || 'application/json'
|
|
},
|
|
signal: options.signal,
|
|
cache: 'default'
|
|
});
|
|
}
|
|
|
|
function post(url, data, options) {
|
|
options ??= {};
|
|
return fetch(combineUrl(url), {
|
|
method: options.method || 'POST',
|
|
headers: {
|
|
...options.customerHeaders,
|
|
'Content-Type': options.contentType || 'application/json'
|
|
},
|
|
body: data,
|
|
signal: options.signal,
|
|
cache: 'no-cache'
|
|
});
|
|
}
|
|
|
|
export {
|
|
get,
|
|
post
|
|
} |