Binato/server/util/AsyncHttpRequest.js

16 lines
353 B
JavaScript
Raw Normal View History

const fetch = require("node-fetch");
2021-02-13 13:01:40 +00:00
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);
}
});
2021-02-13 13:01:40 +00:00
}