mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-28 09:42:21 -04:00
use internal fetch function of node instead external node-fetch
library if node version >= v18
This commit is contained in:
parent
cbda20f67e
commit
0023c64d59
23 changed files with 69 additions and 46 deletions
20
js/fetch.js
Normal file
20
js/fetch.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
/**
|
||||
* 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;
|
Loading…
Add table
Add a link
Reference in a new issue