Skip to content

Commit bc7a9d9

Browse files
motiz88facebook-github-bot
authored andcommitted
Add dev server host/port settings to ReactInstanceConfig (#52263)
Summary: Pull Request resolved: #52263 Changelog: [Internal] Adds a bare-bones API to set the dev server host and port at the time of creating a `ReactInstance` in the C++ platform. Reviewed By: rshest Differential Revision: D77050457 fbshipit-source-id: 642dc96d3cb486a2e7faa177adcbf8a15b8fb668
1 parent 167ec92 commit bc7a9d9

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

packages/react-native/ReactCxxPlatform/react/devsupport/DevServerHelper.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,14 @@ namespace facebook::react {
4545
DevServerHelper::DevServerHelper(
4646
std::string appId,
4747
std::string deviceName,
48+
std::string devServerHost,
49+
uint32_t devServerPort,
4850
const HttpClientFactory& httpClientFactory,
4951
JavaScriptModuleCallback javaScriptModuleCallback) noexcept
5052
: appId_(std::move(appId)),
5153
deviceName_(std::move(deviceName)),
54+
devServerHost_(std::move(devServerHost)),
55+
devServerPort_(devServerPort),
5256
httpClient_(httpClientFactory()),
5357
javaScriptModuleCallback_(std::move(javaScriptModuleCallback)) {
5458
deviceId_ = SHA256(fmt::format("{}-{}", deviceName_, appId_));
@@ -101,8 +105,8 @@ std::string DevServerHelper::getInspectorUrl() const {
101105

102106
return fmt::format(
103107
"ws://{}:{}/inspector/device?name={}&app={}&device={}&profiling={}",
104-
DEFAULT_DEV_SERVER_HOST,
105-
DEFAULT_DEV_SERVER_PORT,
108+
devServerHost_,
109+
devServerPort_,
106110
urlEscape(deviceName_),
107111
appId_,
108112
deviceId_,
@@ -122,8 +126,8 @@ std::string DevServerHelper::getBundleUrl() const {
122126
bool runModule = !splitBundle;
123127
return fmt::format(
124128
"http://{}:{}/{}.bundle?platform={}&dev={}&lazy={}&minify={}&app={}&modulesOnly={}&runModule={}&inlineSourceMap=false&excludeSource=true&sourcePaths=url-server",
125-
DEFAULT_DEV_SERVER_HOST,
126-
DEFAULT_DEV_SERVER_PORT,
129+
devServerHost_,
130+
devServerPort_,
127131
sourcePath_,
128132
DEFAULT_PLATFORM,
129133
dev,
@@ -135,15 +139,14 @@ std::string DevServerHelper::getBundleUrl() const {
135139
};
136140

137141
std::string DevServerHelper::getPackagerConnectionUrl() const {
138-
return fmt::format(
139-
"ws://{}:{}/message", DEFAULT_DEV_SERVER_HOST, DEFAULT_DEV_SERVER_PORT);
142+
return fmt::format("ws://{}:{}/message", devServerHost_, devServerPort_);
140143
}
141144

142145
void DevServerHelper::openDebugger() const {
143146
auto requestUrl = fmt::format(
144147
"http://{}:{}/open-debugger?device={}",
145-
DEFAULT_DEV_SERVER_HOST,
146-
DEFAULT_DEV_SERVER_PORT,
148+
devServerHost_,
149+
devServerPort_,
147150
deviceId_);
148151
httpClient_->sendRequest({}, "POST", requestUrl);
149152
}
@@ -152,8 +155,8 @@ void DevServerHelper::setupHMRClient() const {
152155
folly::dynamic params = folly::dynamic::array(
153156
DEFAULT_PLATFORM,
154157
sourcePath_,
155-
DEFAULT_DEV_SERVER_HOST,
156-
DEFAULT_DEV_SERVER_PORT,
158+
devServerHost_,
159+
devServerPort_,
157160
true /*enable*/);
158161
javaScriptModuleCallback_("HMRClient", "setup", std::move(params));
159162
}

packages/react-native/ReactCxxPlatform/react/devsupport/DevServerHelper.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@
1616

1717
namespace facebook::react {
1818

19-
namespace {
20-
21-
constexpr std::string_view DEFAULT_DEV_SERVER_HOST = "localhost";
22-
constexpr uint32_t DEFAULT_DEV_SERVER_PORT = 8081;
23-
24-
} // namespace
25-
2619
class DevServerHelper {
2720
public:
2821
enum class DownloadProgressStatus : short { STARTED, FAILED, FINISHED };
@@ -31,6 +24,8 @@ class DevServerHelper {
3124
DevServerHelper(
3225
std::string appId,
3326
std::string deviceName,
27+
std::string devServerHost,
28+
uint32_t devServerPort,
3429
const HttpClientFactory& httpClientFactory,
3530
JavaScriptModuleCallback javaScriptModuleCallback) noexcept;
3631
~DevServerHelper() noexcept = default;
@@ -56,6 +51,8 @@ class DevServerHelper {
5651
private:
5752
std::string appId_;
5853
std::string deviceName_;
54+
std::string devServerHost_;
55+
uint32_t devServerPort_;
5956
std::unique_ptr<IHttpClient> httpClient_;
6057
JavaScriptModuleCallback javaScriptModuleCallback_;
6158
std::string deviceId_;

packages/react-native/ReactCxxPlatform/react/runtime/ReactHost.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ void ReactHost::createReactInstance() {
144144
devServerHelper_ = std::make_shared<DevServerHelper>(
145145
reactInstanceConfig_.appId,
146146
reactInstanceConfig_.deviceName,
147+
reactInstanceConfig_.devServerHost,
148+
reactInstanceConfig_.devServerPort,
147149
httpClientFactory,
148150
[this](
149151
const std::string& moduleName,

packages/react-native/ReactCxxPlatform/react/runtime/ReactInstanceConfig.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ struct ReactInstanceConfig {
2020
#endif
2121
std::string appId;
2222
std::string deviceName;
23+
std::string devServerHost{"localhost"};
24+
uint32_t devServerPort{8081};
2325
};
2426

2527
} // namespace facebook::react

0 commit comments

Comments
 (0)