mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
iOS: allow disabling packager access at runtime
Summary: Allow disabling packager access based on the app runtime environment, e.g. running tests. Changelog: [Internal] Differential Revision: D27903019 fbshipit-source-id: cafa25e93efab3cf8e96d60a8fc03de8abb833f4
This commit is contained in:
committed by
Facebook GitHub Bot
parent
96930fad13
commit
6155ad0438
@@ -7,16 +7,19 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#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
|
||||
|
||||
@@ -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]) {
|
||||
|
||||
Reference in New Issue
Block a user