Binato/server/util/AsyncHttpRequest.js
2022-09-30 11:34:13 +01:00

16 lines
No EOL
353 B
JavaScript
Executable file

const fetch = require("node-fetch");
const functionMap = {
"text": async (res) => await res.text(),
"json": async (res) => await res.json()
};
module.exports = async function(url, reqType = "text") {
return new Promise(async (resolve, reject) => {
try {
resolve(functionMap[reqType](await fetch(url)));
} catch (e) {
reject(e);
}
});
}