refactor widget api design

this passes all widget API calls through the backend, with a pluggable design and reusable API handlers
This commit is contained in:
Ben Phelps 2022-09-04 21:58:42 +03:00
parent 975f79f6cc
commit 97bf174b78
27 changed files with 370 additions and 252 deletions

View file

@ -44,3 +44,20 @@ export function httpRequest(url, params) {
request.end();
});
}
export function httpProxy(url, params = {}) {
const constructedUrl = new URL(url);
if (constructedUrl.protocol === "https:") {
const httpsAgent = new https.Agent({
rejectUnauthorized: false,
});
return httpsRequest(constructedUrl, {
agent: httpsAgent,
...params,
});
} else {
return httpRequest(constructedUrl, params);
}
}