Skip to content

Commit ce2c0fe

Browse files
author
Michael Wilkerson-Barker
authored
RCORE-2010 Update default base URL to new domain (#7534)
* Updated default base url to https://services.cloud.mongodb.com * Added default_base_url to bindgen * Updated changelog * Updated App::default_base_url from static var to method * Removed App::default_base_url() from bindgen spec and updated changelog
1 parent c9e206a commit ce2c0fe

File tree

6 files changed

+47
-40
lines changed

6 files changed

+47
-40
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Fix an assertion failure "m_lock_info && m_lock_info->m_file.get_path() == m_filename" that appears to be related to opening a Realm while the file is in the process of being closed on another thread ([Swift #8507](https://github.com/realm/realm-swift/issues/8507)).
99

1010
### Breaking changes
11-
* None.
11+
* Updated default base URL to be `https://services.cloud.mongodb.com` to support the new domains (was `https://realm.mongodb.com`). ([PR #7534](https://github.com/realm/realm-core/pull/7534))
1212

1313
### Compatibility
1414
* Fileformat: Generates files with format v24. Reads and automatically upgrade from fileformat v10. If you want to upgrade from an earlier file format version you will have to use RealmCore v13.x.y or earlier.
@@ -18,6 +18,7 @@
1818
### Internals
1919
* Update libuv used in object store tests from v1.35.0 to v1.48.0 ([PR #7508](https://github.com/realm/realm-core/pull/7508)).
2020
* Made `set_default_logger` nullable in the bindgen spec.yml (PR [#7515](https://github.com/realm/realm-core/pull/7515)).
21+
* Added `App::default_base_url()` static accessor for SDKs to retrieve the default base URL from Core. ([PR #7534](https://github.com/realm/realm-core/pull/7534))
2122

2223
----------------------------------------------
2324

src/realm/object-store/c_api/app.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ static inline bson::BsonArray parse_ejson_array(const char* serialized)
127127

128128
RLM_API const char* realm_app_get_default_base_url(void) noexcept
129129
{
130-
return app::App::default_base_url.data();
130+
return app::App::default_base_url().data();
131131
}
132132

133133
RLM_API realm_app_credentials_t* realm_app_credentials_new_anonymous(bool reuse_credentials) noexcept

src/realm/object-store/sync/app.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,10 @@ std::mutex s_apps_mutex;
183183
namespace realm {
184184
namespace app {
185185

186-
std::string_view App::default_base_url = "https://realm.mongodb.com";
186+
std::string_view App::default_base_url()
187+
{
188+
return "https://services.cloud.mongodb.com";
189+
}
187190

188191
App::Config::DeviceInfo::DeviceInfo()
189192
: platform(util::get_library_platform())
@@ -216,7 +219,7 @@ SharedApp App::get_app(CacheMode mode, const Config& config,
216219
{
217220
if (mode == CacheMode::Enabled) {
218221
std::lock_guard<std::mutex> lock(s_apps_mutex);
219-
auto& app = s_apps_cache[config.app_id][config.base_url.value_or(std::string(default_base_url))];
222+
auto& app = s_apps_cache[config.app_id][config.base_url.value_or(std::string(App::default_base_url()))];
220223
if (!app) {
221224
app = std::make_shared<App>(Private(), config);
222225
app->configure(sync_client_config);
@@ -262,7 +265,7 @@ void App::close_all_sync_sessions()
262265

263266
App::App(Private, const Config& config)
264267
: m_config(config)
265-
, m_base_url(m_config.base_url.value_or(std::string(default_base_url)))
268+
, m_base_url(m_config.base_url.value_or(std::string(App::default_base_url())))
266269
, m_location_updated(false)
267270
, m_request_timeout_ms(m_config.default_request_timeout_ms.value_or(s_default_timeout_ms))
268271
{
@@ -395,7 +398,7 @@ void App::configure_route(const std::string& host_url, const std::optional<std::
395398
m_ws_host_url = App::create_ws_host_url(m_host_url);
396399
}
397400

398-
// host_url is the url to the server: e.g., https://realm.mongodb.com or https://localhost:9090
401+
// host_url is the url to the server: e.g., https://services.cloud.mongodb.com or https://localhost:9090
399402
// base_route is the baseline client api path: e.g. <host_url>/api/client/v2.0
400403
m_base_route = util::format("%1%2", m_host_url, s_base_path);
401404
// app_route is the cloud app URL: <host_url>/api/client/v2.0/app/<app_id>
@@ -412,7 +415,7 @@ void App::configure_route(const std::string& host_url, const std::optional<std::
412415
// All others => http[s]://<host-url> => ws[s]://<host-url>
413416
std::string App::create_ws_host_url(const std::string_view host_url)
414417
{
415-
constexpr static std::string_view orig_base_domain = "realm.mongodb.com";
418+
constexpr static std::string_view old_base_domain = "realm.mongodb.com";
416419
constexpr static std::string_view new_base_domain = "services.cloud.mongodb.com";
417420
const size_t base_len = std::char_traits<char>::length("http://");
418421

@@ -428,7 +431,7 @@ std::string App::create_ws_host_url(const std::string_view host_url)
428431

429432
// http[s]://[<region-prefix>]realm.mongodb.com[/<path>] =>
430433
// ws[s]://ws.[<region-prefix>]realm.mongodb.com[/<path>]
431-
if (host_url.find(orig_base_domain) != std::string_view::npos) {
434+
if (host_url.find(old_base_domain) != std::string_view::npos) {
432435
return util::format("%1ws.%2", prefix, host_url.substr(prefix_len));
433436
}
434437
// http[s]://[<region-prefix>]services.cloud.mongodb.com[/<path>] =>
@@ -653,11 +656,11 @@ std::string App::get_base_url() const
653656

654657
void App::update_base_url(std::optional<std::string> base_url, UniqueFunction<void(Optional<AppError>)>&& completion)
655658
{
656-
std::string new_base_url = base_url.value_or(std::string(default_base_url));
659+
std::string new_base_url = base_url.value_or(std::string(App::default_base_url()));
657660

658661
if (new_base_url.empty()) {
659662
// Treat an empty string the same as requesting the default base url
660-
new_base_url = default_base_url;
663+
new_base_url = std::string(App::default_base_url());
661664
log_debug("App::update_base_url: empty => %1", new_base_url);
662665
}
663666
else {

src/realm/object-store/sync/app.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ class App : public std::enable_shared_from_this<App>,
9090
DeviceInfo device_info;
9191
};
9292

93-
static std::string_view default_base_url;
93+
// Returns the default base_url for SDKs to use instead of defining their own
94+
static std::string_view default_base_url();
9495

9596
// `enable_shared_from_this` is unsafe with public constructors;
9697
// use `App::get_app()` instead
@@ -444,18 +445,18 @@ class App : public std::enable_shared_from_this<App>,
444445
// The following variables hold the different paths to Atlas, depending on the
445446
// request being performed
446447
// Base hostname from config.base_url or update_base_url() for querying location info
447-
// (e.g. "https://realm.mongodb.com")
448+
// (e.g. "https://services.cloud.mongodb.com")
448449
std::string m_base_url GUARDED_BY(m_route_mutex);
449450
// Baseline URL for AppServices and Device Sync requests
450-
// (e.g. "https://us-east-1.aws.realm.mongodb.com/api/client/v2.0" or
451-
// "wss://ws.us-east-1.aws.realm.mongodb.com/api/client/v2.0")
451+
// (e.g. "https://us-east-1.aws.services.cloud.mongodb.com/api/client/v2.0" or
452+
// "wss://us-east-1.aws.ws.services.cloud.mongodb.com/api/client/v2.0")
452453
std::string m_base_route GUARDED_BY(m_route_mutex);
453454
// URL for app-based AppServices and Device Sync requests using config.app_id
454-
// (e.g. "https://us-east-1.aws.realm.mongodb.com/api/client/v2.0/app/<app_id>"
455-
// or "wss://ws.us-east-1.aws.realm.mongodb.com/api/client/v2.0/app/<app_id>")
455+
// (e.g. "https://us-east-1.aws.services.cloud.mongodb.com/api/client/v2.0/app/<app_id>"
456+
// or "wss://us-east-1.aws.ws.services.cloud.mongodb.com/api/client/v2.0/app/<app_id>")
456457
std::string m_app_route GUARDED_BY(m_route_mutex);
457458
// URL for app-based AppServices authentication requests (e.g. email/password)
458-
// (e.g. "https://us-east-1.aws.realm.mongodb.com/api/client/v2.0/app/<app_id>/auth")
459+
// (e.g. "https://us-east-1.aws.services.cloud.mongodb.com/api/client/v2.0/app/<app_id>/auth")
459460
std::string m_auth_route GUARDED_BY(m_route_mutex);
460461
// If false, the location info will be updated upon the next AppServices request
461462
bool m_location_updated GUARDED_BY(m_route_mutex);

test/object-store/c_api/c_api.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ TEST_CASE("C API (non-database)", "[c_api]") {
605605
CHECK(app_config->app_id == "app_id_123");
606606
CHECK(app_config->transport == transport);
607607

608-
CHECK(realm_app_get_default_base_url() == app::App::default_base_url);
608+
CHECK(realm_app_get_default_base_url() == app::App::default_base_url());
609609

610610
CHECK(!app_config->base_url);
611611
realm_app_config_set_base_url(app_config.get(), base_url.c_str());
@@ -695,13 +695,13 @@ TEST_CASE("C API (non-database)", "[c_api]") {
695695
check_base_url(base_url);
696696

697697
// Reset to the default base url using nullptr
698-
update_and_check_base_url(nullptr, app::App::default_base_url);
698+
update_and_check_base_url(nullptr, app::App::default_base_url());
699699

700700
// Set to some other base url
701701
update_and_check_base_url(base_url2.c_str(), base_url2);
702702

703703
// Reset to default base url using empty string
704-
update_and_check_base_url("", app::App::default_base_url);
704+
update_and_check_base_url("", app::App::default_base_url());
705705

706706
realm_release(sync_user);
707707
realm_release(token);

test/object-store/sync/app.cpp

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3962,6 +3962,7 @@ TEST_CASE("app: base_url", "[sync][app][base_url]") {
39623962
CHECK(result == "ws://172.0.0.1:9090");
39633963
result = App::create_ws_host_url("https://172.0.0.1:9090");
39643964
CHECK(result == "wss://172.0.0.1:9090");
3965+
// Old default base url
39653966
result = App::create_ws_host_url("http://realm.mongodb.com");
39663967
CHECK(result == "ws://ws.realm.mongodb.com");
39673968
result = App::create_ws_host_url("https://realm.mongodb.com");
@@ -3974,6 +3975,7 @@ TEST_CASE("app: base_url", "[sync][app][base_url]") {
39743975
CHECK(result == "wss://ws.us-east-1.aws.realm.mongodb.com");
39753976
result = App::create_ws_host_url("https://us-east-1.aws.realm.mongodb.com/some/extra/stuff");
39763977
CHECK(result == "wss://ws.us-east-1.aws.realm.mongodb.com/some/extra/stuff");
3978+
// New default base url
39773979
result = App::create_ws_host_url("http://services.cloud.mongodb.com");
39783980
CHECK(result == "ws://ws.services.cloud.mongodb.com");
39793981
result = App::create_ws_host_url("https://services.cloud.mongodb.com");
@@ -3990,21 +3992,21 @@ TEST_CASE("app: base_url", "[sync][app][base_url]") {
39903992

39913993
SECTION("Test app config baseurl") {
39923994
{
3993-
redir_transport->reset(App::default_base_url);
3995+
redir_transport->reset(App::default_base_url());
39943996

3995-
// First time through, base_url is empty; https://realm.mongodb.com is expected
3997+
// First time through, base_url is empty; https://services.cloud.mongodb.com is expected
39963998
auto app = app::App::get_app(app::App::CacheMode::Disabled, app_config, sc_config);
39973999
// Location is not requested until first app services request
39984000
CHECK(!redir_transport->location_requested);
39994001
// Initial hostname and ws hostname use base url, but aren't used until location is updated
4000-
CHECK(app->get_host_url() == App::default_base_url);
4001-
CHECK(app->get_ws_host_url() == App::create_ws_host_url(App::default_base_url));
4002+
CHECK(app->get_host_url() == App::default_base_url());
4003+
CHECK(app->get_ws_host_url() == App::create_ws_host_url(App::default_base_url()));
40024004

40034005
do_login(app);
40044006
CHECK(redir_transport->location_requested);
4005-
CHECK(app->get_base_url() == App::default_base_url);
4006-
CHECK(app->get_host_url() == App::default_base_url);
4007-
CHECK(app->get_ws_host_url() == App::create_ws_host_url(App::default_base_url));
4007+
CHECK(app->get_base_url() == App::default_base_url());
4008+
CHECK(app->get_host_url() == App::default_base_url());
4009+
CHECK(app->get_ws_host_url() == App::create_ws_host_url(App::default_base_url()));
40084010
}
40094011
{
40104012
// Second time through, base_url is set to https://alternate.someurl.fake is expected
@@ -4025,11 +4027,11 @@ TEST_CASE("app: base_url", "[sync][app][base_url]") {
40254027
CHECK(app->get_ws_host_url() == "wss://alternate.someurl.fake");
40264028
}
40274029
{
4028-
// Third time through, base_url is not set, expect https://realm.mongodb.com, since metadata
4029-
// is no longer used
4030+
// Third time through, base_url is not set, expect https://services.cloud.mongodb.com,
4031+
// since metadata is no longer used
40304032
app_config.base_url = util::none;
4031-
std::string expected_url = std::string(App::default_base_url);
4032-
std::string expected_wsurl = App::create_ws_host_url(App::default_base_url);
4033+
std::string expected_url = std::string(App::default_base_url());
4034+
std::string expected_wsurl = App::create_ws_host_url(App::default_base_url());
40334035
redir_transport->reset(expected_url);
40344036

40354037
auto app = app::App::get_app(app::App::CacheMode::Disabled, app_config, sc_config);
@@ -4082,16 +4084,16 @@ TEST_CASE("app: base_url", "[sync][app][base_url]") {
40824084
CHECK(app->get_host_url() == "https://alternate.someurl.fake");
40834085
CHECK(app->get_ws_host_url() == "wss://alternate.someurl.fake");
40844086

4085-
redir_transport->reset(App::default_base_url);
4087+
redir_transport->reset(App::default_base_url());
40864088

40874089
// Revert the base URL to the default URL value using std::nullopt
40884090
app->update_base_url(std::nullopt, [](util::Optional<app::AppError> error) {
40894091
CHECK(!error);
40904092
});
40914093
CHECK(redir_transport->location_requested);
4092-
CHECK(app->get_base_url() == App::default_base_url);
4093-
CHECK(app->get_host_url() == App::default_base_url);
4094-
CHECK(app->get_ws_host_url() == App::create_ws_host_url(App::default_base_url));
4094+
CHECK(app->get_base_url() == App::default_base_url());
4095+
CHECK(app->get_host_url() == App::default_base_url());
4096+
CHECK(app->get_ws_host_url() == App::create_ws_host_url(App::default_base_url()));
40954097
// Expected URL is still App::default_base_url
40964098
do_login(app);
40974099

@@ -4106,16 +4108,16 @@ TEST_CASE("app: base_url", "[sync][app][base_url]") {
41064108
// Expected URL is still "http://some-other.url.fake"
41074109
do_login(app);
41084110

4109-
redir_transport->reset(App::default_base_url);
4111+
redir_transport->reset(App::default_base_url());
41104112

41114113
// Revert the base URL to the default URL value using the empty string
41124114
app->update_base_url("", [](util::Optional<app::AppError> error) {
41134115
CHECK(!error);
41144116
});
41154117
CHECK(redir_transport->location_requested);
4116-
CHECK(app->get_base_url() == App::default_base_url);
4117-
CHECK(app->get_host_url() == App::default_base_url);
4118-
CHECK(app->get_ws_host_url() == App::create_ws_host_url(App::default_base_url));
4118+
CHECK(app->get_base_url() == App::default_base_url());
4119+
CHECK(app->get_host_url() == App::default_base_url());
4120+
CHECK(app->get_ws_host_url() == App::create_ws_host_url(App::default_base_url()));
41194121
// Expected URL is still App::default_base_url
41204122
do_login(app);
41214123
}
@@ -5804,7 +5806,7 @@ TEST_CASE("app: shared instances", "[sync][app]") {
58045806

58055807
auto config2 = base_config;
58065808
config2.app_id = "app1";
5807-
config2.base_url = std::string(App::default_base_url);
5809+
config2.base_url = std::string(App::default_base_url());
58085810

58095811
auto config3 = base_config;
58105812
config3.app_id = "app2";

0 commit comments

Comments
 (0)