Skip to content

Commit afdb609

Browse files
cipolleschifacebook-github-bot
authored andcommitted
Fix iOS inspector getServerHost to handle HTTPS correctly
Summary: ## Summary: Update `getServerHost()` in `RCTInspectorDevServerHelper` to properly handle HTTPS connections. When the bundle URL uses HTTPS, the port is omitted from the host string (the scheme implies 443). The explicit port from the URL takes priority, followed by the `RCT_METRO_PORT` environment variable, with 8081 as the default fallback for local development. ## Changelog: [IOS][FIXED] - Fix inspector server host resolution for HTTPS bundle URLs by omitting default port ## Test Plan: Verified that getServerHost returns: - `host:port` when an explicit port is in the URL - `host:envPort` when RCT_METRO_PORT is set - `host` (no port) when the scheme is https - `host:8081` as the default fallback ## Facebook: Applied from nest/mobile/apps/atod-sample/patches/react-native+0.83.1+008+atod-ios-ws-fixes.patch Reviewed By: cortinico Differential Revision: D95038004
1 parent 23e4c7d commit afdb609

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

packages/react-native/React/DevSupport/RCTInspectorDevServerHelper.mm

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,29 @@
2323

2424
static NSString *getServerHost(NSURL *bundleURL)
2525
{
26-
NSNumber *port = @8081;
27-
NSString *portStr = [[[NSProcessInfo processInfo] environment] objectForKey:@"RCT_METRO_PORT"];
28-
if ((portStr != nullptr) && [portStr length] > 0) {
29-
port = [NSNumber numberWithInt:[portStr intValue]];
30-
}
31-
if ([bundleURL port] != nullptr) {
32-
port = [bundleURL port];
33-
}
3426
NSString *host = [bundleURL host];
3527
if (host == nullptr) {
3628
host = @"localhost";
3729
}
3830

39-
// this is consistent with the Android implementation, where http:// is the
40-
// hardcoded implicit scheme for the debug server. Note, packagerURL
41-
// technically looks like it could handle schemes/protocols other than HTTP,
42-
// so rather than force HTTP, leave it be for now, in case someone is relying
43-
// on that ability when developing against iOS.
44-
return [NSString stringWithFormat:@"%@:%@", host, port];
31+
// Use explicit port from URL if available
32+
if ([bundleURL port] != nullptr) {
33+
return [NSString stringWithFormat:@"%@:%@", host, [bundleURL port]];
34+
}
35+
36+
// Check environment variable
37+
NSString *portStr = [[[NSProcessInfo processInfo] environment] objectForKey:@"RCT_METRO_PORT"];
38+
if ((portStr != nullptr) && [portStr length] > 0) {
39+
return [NSString stringWithFormat:@"%@:%@", host, portStr];
40+
}
41+
42+
// For https, omit port — the scheme implies 443
43+
if ([[bundleURL scheme] isEqualToString:@"https"]) {
44+
return host;
45+
}
46+
47+
// Default to 8081 for local development (Metro's default port)
48+
return [NSString stringWithFormat:@"%@:%@", host, @8081];
4549
}
4650

4751
static NSString *getSHA256(NSString *string)

0 commit comments

Comments
 (0)