Skip to content

Commit 7006a1f

Browse files
committed
add Node.js fallback for file util
Check whether XMLHttpRequest is defined and if not use the Node.js built-in fetch method.
1 parent f114b2c commit 7006a1f

File tree

1 file changed

+10
-5
lines changed
  • packages/mesh-common/src/utils

1 file changed

+10
-5
lines changed
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
export function getFile(url: string) {
2-
var Httpreq = new XMLHttpRequest();
3-
Httpreq.open("GET", url, false);
4-
Httpreq.send(null);
5-
return Httpreq.responseText;
1+
export async function getFile(url: string) {
2+
if (typeof XMLHttpRequest !== "undefined") {
3+
var Httpreq = new XMLHttpRequest();
4+
Httpreq.open("GET", url, false);
5+
Httpreq.send(null);
6+
return Httpreq.responseText;
7+
} else {
8+
const res = await fetch(url);
9+
return res.text();
10+
}
611
}

0 commit comments

Comments
 (0)