Support opening Realms with an admin token without a working ROS directory service (#1615)

* Support opening Realms with an admin token without a working ROS directory service
This commit is contained in:
Thomas Goyne 2018-01-13 01:02:08 -08:00 committed by Kenneth Geisshirt
parent af21ae6bd8
commit b9cce49972
2 changed files with 30 additions and 4 deletions

View File

@ -1,3 +1,17 @@
X.Y.Z Release notes
=============================================================
### Breaking changes
* None.
### Enhancements
* None.
### Bug fixes
* [Object Server] Fixed a bug preventing opening Realms with an admin token without a working ROS directory service (#1615).
### Internal
* None.
2.2.0 Release notes (2018-1-12) 2.2.0 Release notes (2018-1-12)
============================================================= =============================================================
### Breaking changes ### Breaking changes
@ -12,9 +26,7 @@
### Bug fixes ### Bug fixes
* Fix a bug where `Realm.open` could unexpectedly raise a "Realm at path ... already opened with different schema version" error. * Fix a bug where `Realm.open` could unexpectedly raise a "Realm at path ... already opened with different schema version" error.
* `subscribeToObjects` was added as a property for Chrome debugging (#1608). * `subscribeToObjects` was added as a property for Chrome debugging (#1608).
* Increased request timeout for token refresh requests to 10 seconds. This * Increased request timeout for token refresh requests to 10 seconds. This should help with failing token refreshes on a loaded server (#1586).
should help with failing token refreshes on a loaded server (#1586).
* Increased request timeout for token refresh requests to 10 seconds. This should help with failing token refreshes on a loaded server.
### Internal ### Internal
* Updated to Realm Sync 2.2.9. * Updated to Realm Sync 2.2.9.

View File

@ -92,7 +92,21 @@ function refreshAdminToken(user, localRealmPath, realmUrl) {
let parsedRealmUrl = url_parse(realmUrl); let parsedRealmUrl = url_parse(realmUrl);
const url = append_url(user.server, 'realms/files/' + encodeURIComponent(parsedRealmUrl.pathname)); const url = append_url(user.server, 'realms/files/' + encodeURIComponent(parsedRealmUrl.pathname));
performFetch(url, {method: 'GET', timeout: 10000.0, headers: {Authorization: user.token}}) performFetch(url, {method: 'GET', timeout: 10000.0, headers: {Authorization: user.token}})
.then((response) => response.json().then((json) => { return { response, json }; })) .then((response) => {
// There may not be a Realm Directory Service running on the server
// we're talking to. If we're talking directly to the sync service
// we'll get a 404, and if we're running inside ROS we'll get a 503 if
// the directory service hasn't started yet (perhaps because we got
// called due to the directory service itself opening some Realms).
//
// In both of these cases we can just pretend we got a valid response.
if (response.status === 404 || response.status === 503) {
return {response: {status: 200}, json: {path: parsedRealmUrl.pathname, syncLabel: '_direct'}};
}
else {
return response.json().then((json) => { return { response, json }; });
}
})
.then((responseAndJson) => { .then((responseAndJson) => {
const response = responseAndJson.response; const response = responseAndJson.response;
const json = responseAndJson.json; const json = responseAndJson.json;