|
20 | 20 | #import <jsinspector-modern/InspectorFlags.h> |
21 | 21 |
|
22 | 22 | static NSString *const kDebuggerMsgDisable = @"{ \"id\":1,\"method\":\"Debugger.disable\" }"; |
| 23 | +static const int kDefaultMetroPort = 8081; |
23 | 24 |
|
24 | 25 | static NSString *getServerHost(NSURL *bundleURL) |
25 | 26 | { |
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 | | - } |
34 | 27 | NSString *host = [bundleURL host]; |
35 | 28 | if (host == nullptr) { |
36 | 29 | host = @"localhost"; |
37 | 30 | } |
38 | 31 |
|
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]; |
45 | 50 | } |
46 | 51 |
|
47 | 52 | static NSString *getSHA256(NSString *string) |
|
112 | 117 | NSString *escapedInspectorDeviceId = [getInspectorDeviceId() |
113 | 118 | stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLQueryAllowedCharacterSet]; |
114 | 119 |
|
115 | | - return [NSURL |
116 | | - URLWithString:[NSString stringWithFormat:@"http://%@/inspector/device?name=%@&app=%@&device=%@&profiling=%@", |
117 | | - getServerHost(bundleURL), |
118 | | - escapedDeviceName, |
119 | | - escapedAppName, |
120 | | - escapedInspectorDeviceId, |
121 | | - isProfilingBuild ? @"true" : @"false"]]; |
| 120 | + NSString *scheme = [bundleURL scheme] != nullptr ? [bundleURL scheme] : @"http"; |
| 121 | + return |
| 122 | + [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@/inspector/device?name=%@&app=%@&device=%@&profiling=%@", |
| 123 | + scheme, |
| 124 | + getServerHost(bundleURL), |
| 125 | + escapedDeviceName, |
| 126 | + escapedAppName, |
| 127 | + escapedInspectorDeviceId, |
| 128 | + isProfilingBuild ? @"true" : @"false"]]; |
122 | 129 | } |
123 | 130 |
|
124 | 131 | @implementation RCTInspectorDevServerHelper |
@@ -150,7 +157,9 @@ + (void)openDebugger:(NSURL *)bundleURL withErrorMessage:(NSString *)errorMessag |
150 | 157 | NSString *escapedInspectorDeviceId = [getInspectorDeviceId() |
151 | 158 | stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLQueryAllowedCharacterSet]; |
152 | 159 |
|
153 | | - NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@/open-debugger?device=%@", |
| 160 | + NSString *scheme = [bundleURL scheme] != nullptr ? [bundleURL scheme] : @"http"; |
| 161 | + NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@/open-debugger?device=%@", |
| 162 | + scheme, |
154 | 163 | getServerHost(bundleURL), |
155 | 164 | escapedInspectorDeviceId]]; |
156 | 165 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; |
|
0 commit comments