Skip to content

Commit 4b11ecf

Browse files
Fix serve and staticpkg (microsoft#4720)
1 parent 5006c0a commit 4b11ecf

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

pxtlib/emitter/cloud.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace pxt.Cloud {
22
import Util = pxtc.Util;
33

44
// hit /api/ to stay on same domain and avoid CORS
5-
export let apiRoot = isLocalHost() ? "https://www.makecode.com/api/" : "/api/";
5+
export let apiRoot = isLocalHost() || Util.isNodeJS ? "https://www.makecode.com/api/" : "/api/";
66
export let accessToken = "";
77
export let localToken = "";
88
let _isOnline = true;
@@ -97,7 +97,7 @@ namespace pxt.Cloud {
9797
.then(db => db.getAsync(locale, docid, "")
9898
.then(entry => {
9999
if (entry && Date.now() - entry.time > MARKDOWN_EXPIRATION)
100-
// background update,
100+
// background update,
101101
downloadMarkdownAsync(docid, locale, live, entry.etag)
102102
.then(r => db.setAsync(locale, docid, branch, r.etag, undefined, r.md || entry.md))
103103
.catch(() => { }) // swallow errors

pxtlib/util.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,8 @@ namespace ts.pxtc.Util {
446446
return a + b;
447447
}
448448

449-
export let isNodeJS = false;
449+
// Reliable NodeJS detection is not possible, but the following check should be accurate enough for our needs
450+
export let isNodeJS = typeof window === "undefined";
450451

451452
export interface HttpRequestOptions {
452453
url: string;

0 commit comments

Comments
 (0)