diff --git a/React/Base/RCTBundleURLProvider.h b/React/Base/RCTBundleURLProvider.h index 6e1dea3a66a..890f8c3819a 100644 --- a/React/Base/RCTBundleURLProvider.h +++ b/React/Base/RCTBundleURLProvider.h @@ -7,16 +7,19 @@ #import -#if defined(__cplusplus) -extern "C" { -#endif +#import "RCTDefines.h" -extern NSString *const RCTBundleURLProviderUpdatedNotification; +RCT_EXTERN NSString *const RCTBundleURLProviderUpdatedNotification; +RCT_EXTERN const NSUInteger kRCTBundleURLProviderDefaultPort; -extern const NSUInteger kRCTBundleURLProviderDefaultPort; - -#if defined(__cplusplus) -} +#if RCT_DEV_MENU +/** + * Allow/disallow accessing the packager server for various runtime scenario. + * For instance, if a test run should never access the packager, disable it + * by calling this function before initializing React Native (RCTBridge etc). + * By default the access is enabled. + */ +RCT_EXTERN void RCTBundleURLProviderAllowPackagerServerAccess(BOOL allowed); #endif @interface RCTBundleURLProvider : NSObject diff --git a/React/Base/RCTBundleURLProvider.mm b/React/Base/RCTBundleURLProvider.mm index cda955fe9f0..393ca563102 100644 --- a/React/Base/RCTBundleURLProvider.mm +++ b/React/Base/RCTBundleURLProvider.mm @@ -9,11 +9,20 @@ #import "RCTConvert.h" #import "RCTDefines.h" +#import "RCTLog.h" NSString *const RCTBundleURLProviderUpdatedNotification = @"RCTBundleURLProviderUpdatedNotification"; const NSUInteger kRCTBundleURLProviderDefaultPort = RCT_METRO_PORT; +#if RCT_DEV_MENU +static BOOL kRCTAllowPackagerAccess = YES; +void RCTBundleURLProviderAllowPackagerServerAccess(BOOL allowed) +{ + kRCTAllowPackagerAccess = allowed; +} +#endif + static NSString *const kRCTJsLocationKey = @"RCT_jsLocation"; static NSString *const kRCTEnableDevKey = @"RCT_enableDev"; static NSString *const kRCTEnableMinificationKey = @"RCT_enableMinification"; @@ -127,6 +136,12 @@ static NSURL *serverRootWithHostPort(NSString *hostPort) - (NSString *)packagerServerHostPort { +#if RCT_DEV_MENU + if (!kRCTAllowPackagerAccess) { + RCTLogInfo(@"Packager server access is disabled in this environment"); + return nil; + } +#endif NSString *location = [self jsLocation]; #if RCT_DEV_MENU if ([location length] && ![RCTBundleURLProvider isPackagerRunning:location]) {