Skip to content

Commit 3582a8b

Browse files
cipolleschimeta-codesync[bot]
authored andcommitted
Fix iOS inspector getServerHost to handle HTTPS correctly (#55872)
Summary: Pull Request resolved: #55872 ## 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 fbshipit-source-id: 38b6f54b9e7f0346ef7ee4411099ef055769685b
1 parent 36dfcef commit 3582a8b

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

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

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,33 @@
2020
#import <jsinspector-modern/InspectorFlags.h>
2121

2222
static NSString *const kDebuggerMsgDisable = @"{ \"id\":1,\"method\":\"Debugger.disable\" }";
23+
static const int kDefaultMetroPort = 8081;
2324

2425
static NSString *getServerHost(NSURL *bundleURL)
2526
{
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-
}
3427
NSString *host = [bundleURL host];
3528
if (host == nullptr) {
3629
host = @"localhost";
3730
}
3831

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];
32+
// Use explicit port from URL if available
33+
if ([bundleURL port] != nullptr) {
34+
return [NSString stringWithFormat:@"%@:%@", host, [bundleURL port]];
35+
}
36+
37+
// Check environment variable
38+
NSString *portStr = [[[NSProcessInfo processInfo] environment] objectForKey:@"RCT_METRO_PORT"];
39+
if ((portStr != nullptr) && [portStr length] > 0) {
40+
return [NSString stringWithFormat:@"%@:%@", host, portStr];
41+
}
42+
43+
// For https, omit port — the scheme implies 443
44+
if ([[bundleURL scheme] isEqualToString:@"https"]) {
45+
return host;
46+
}
47+
48+
// Default to 8081 for local development (Metro's default port)
49+
return [NSString stringWithFormat:@"%@:%d", host, kDefaultMetroPort];
4550
}
4651

4752
static NSString *getSHA256(NSString *string)

0 commit comments

Comments
 (0)