multiple libraries, add request and cookie

This commit is contained in:
2023-03-30 00:20:35 +08:00
parent ad8fe8fa85
commit 1d636cdc79
11 changed files with 143 additions and 23 deletions

38
lib/utility/request.js Normal file
View File

@ -0,0 +1,38 @@
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
}