mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 03:39:55 +00:00
small update to the fetchData method to use the fetch helper instead of the old XCMLHttpRequest. Also fixes some typos :-) Co-authored-by: veeck <michael@veeck.de>
21 lines
448 B
JavaScript
21 lines
448 B
JavaScript
/**
|
|
* fetch
|
|
*
|
|
* @param {string} url to be fetched
|
|
* @param {object} options object e.g. for headers
|
|
* @class
|
|
*/
|
|
async function fetch(url, options = {}) {
|
|
const nodeVersion = process.version.match(/^v(\d+)\.*/)[1];
|
|
if (nodeVersion >= 18) {
|
|
// node version >= 18
|
|
return global.fetch(url, options);
|
|
} else {
|
|
// node version < 18
|
|
const nodefetch = require("node-fetch");
|
|
return nodefetch(url, options);
|
|
}
|
|
}
|
|
|
|
module.exports = fetch;
|