aboutsummaryrefslogtreecommitdiffhomepage
path: root/Functions/FirebaseFunctions
diff options
context:
space:
mode:
authorGravatar Bryan Klimt <bklimt@gmail.com>2018-06-21 15:25:13 -0400
committerGravatar GitHub <noreply@github.com>2018-06-21 15:25:13 -0400
commitf08edbb85c5cbde74c354c478ac9433d2417d748 (patch)
treec837525029c9657ccf6edbc41e52952bab6f5f60 /Functions/FirebaseFunctions
parentb271a6e25144be8cf872d028bb82336b5da2074c (diff)
Add a couple of new small Functions APIs. (#1434)
* Add a Functions constructor that allows setting a region. * Add a method to set an emulator origin to use. * Update the changelog
Diffstat (limited to 'Functions/FirebaseFunctions')
-rw-r--r--Functions/FirebaseFunctions/FIRFunctions.m19
-rw-r--r--Functions/FirebaseFunctions/Public/FIRFunctions.h13
2 files changed, 21 insertions, 11 deletions
diff --git a/Functions/FirebaseFunctions/FIRFunctions.m b/Functions/FirebaseFunctions/FIRFunctions.m
index 274d058..5a67d86 100644
--- a/Functions/FirebaseFunctions/FIRFunctions.m
+++ b/Functions/FirebaseFunctions/FIRFunctions.m
@@ -43,9 +43,8 @@ NSString *const kFUNInstanceIDTokenHeader = @"Firebase-Instance-ID-Token";
FUNSerializer *_serializer;
// A factory for getting the metadata to include with function calls.
FUNContextProvider *_contextProvider;
- // For testing only. If this is set, functions will be called against localhost instead of
- // Firebase.
- BOOL _useLocalhost;
+ // For testing only. If this is set, functions will be called against it instead of Firebase.
+ NSString *_emulatorOrigin;
}
/**
@@ -86,13 +85,17 @@ NSString *const kFUNInstanceIDTokenHeader = @"Firebase-Instance-ID-Token";
_region = [region copy];
_serializer = [[FUNSerializer alloc] init];
_contextProvider = [[FUNContextProvider alloc] initWithApp:app];
- _useLocalhost = NO;
+ _emulatorOrigin = nil;
}
return self;
}
- (void)useLocalhost {
- _useLocalhost = YES;
+ [self useFunctionsEmulatorOrigin:@"http://localhost:5005"];
+}
+
+- (void)useFunctionsEmulatorOrigin:(NSString *)origin {
+ _emulatorOrigin = origin;
}
- (NSString *)URLWithName:(NSString *)name {
@@ -103,8 +106,8 @@ NSString *const kFUNInstanceIDTokenHeader = @"Firebase-Instance-ID-Token";
if (!projectID) {
FUNThrowInvalidArgument(@"FIRFunctions app projectID cannot be nil.");
}
- if (_useLocalhost) {
- return [NSString stringWithFormat:@"http://localhost:5005/%@/%@/%@", projectID, _region, name];
+ if (_emulatorOrigin) {
+ return [NSString stringWithFormat:@"%@/%@/%@/%@", _emulatorOrigin, projectID, _region, name];
}
return
[NSString stringWithFormat:@"https://%@-%@.cloudfunctions.net/%@", _region, projectID, name];
@@ -166,7 +169,7 @@ NSString *const kFUNInstanceIDTokenHeader = @"Firebase-Instance-ID-Token";
}
// Override normal security rules if this is a local test.
- if (_useLocalhost) {
+ if (_emulatorOrigin) {
fetcher.allowLocalhostRequest = YES;
fetcher.allowedInsecureSchemes = @[ @"http" ];
}
diff --git a/Functions/FirebaseFunctions/Public/FIRFunctions.h b/Functions/FirebaseFunctions/Public/FIRFunctions.h
index d01175c..98d7a67 100644
--- a/Functions/FirebaseFunctions/Public/FIRFunctions.h
+++ b/Functions/FirebaseFunctions/Public/FIRFunctions.h
@@ -42,7 +42,7 @@ NS_SWIFT_NAME(Functions)
* Creates a Cloud Functions client with the default app and given region.
* @param region The region for the http trigger, such as "us-central1".
*/
-// + (instancetype)functionsForRegion:(NSString *)region NS_SWIFT_NAME(functions(region:));
++ (instancetype)functionsForRegion:(NSString *)region NS_SWIFT_NAME(functions(region:));
/**
* Creates a Cloud Functions client with the given app and region.
@@ -51,8 +51,8 @@ NS_SWIFT_NAME(Functions)
*/
// clang-format off
// because it incorrectly breaks this NS_SWIFT_NAME.
-// + (instancetype)functionsForApp:(FIRApp *)app
-// region:(NSString *)region NS_SWIFT_NAME(functions(app:region:));
++ (instancetype)functionsForApp:(FIRApp *)app
+ region:(NSString *)region NS_SWIFT_NAME(functions(app:region:));
// clang-format on
/**
@@ -61,6 +61,13 @@ NS_SWIFT_NAME(Functions)
*/
- (FIRHTTPSCallable *)HTTPSCallableWithName:(NSString *)name NS_SWIFT_NAME(httpsCallable(_:));
+/**
+ * Changes this instance to point to a Cloud Functions emulator running locally.
+ * See https://firebase.google.com/docs/functions/local-emulator
+ * @param origin The origin of the local emulator, such as "http://localhost:5005".
+ */
+- (void)useFunctionsEmulatorOrigin:(NSString *)origin NS_SWIFT_NAME(useFunctionsEmulator(origin:));
+
@end
NS_ASSUME_NONNULL_END