Skip to content

Commit 33afe1e

Browse files
leeyehwangxiao
authored andcommitted
fix: use proper closure to prevent getServerURLPromise from being resolved more then once (#332)
1 parent 9d927bd commit 33afe1e

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/request.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,10 @@ const refreshServerUrlByRouter = () => {
252252

253253
const setServerUrlByRegion = (region = 'cn') => {
254254
getServerURLPromise = new AVPromise();
255+
const promise = getServerURLPromise;
255256
// 如果用户在 init 之前设置了 APIServerURL,则跳过请求 router
256257
if (AV._config.APIServerURL) {
257-
getServerURLPromise.resolve();
258+
promise.resolve();
258259
return;
259260
}
260261
// if not china server region, do not use router
@@ -266,14 +267,14 @@ const setServerUrlByRegion = (region = 'cn') => {
266267
return refreshServerUrlByRouter();
267268
}
268269
}).then(() => {
269-
getServerURLPromise.resolve();
270+
promise.resolve();
270271
}).catch((error) => {
271-
getServerURLPromise.reject(error);
272+
promise.reject(error);
272273
});
273274
} else {
274275
AV._config.region = region;
275276
AV._config.APIServerURL = API_HOST[region];
276-
getServerURLPromise.resolve();
277+
promise.resolve();
277278
}
278279
};
279280

0 commit comments

Comments
 (0)