diff options
author | Bryan Klimt <bklimt@gmail.com> | 2018-06-21 15:25:13 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-21 15:25:13 -0400 |
commit | f08edbb85c5cbde74c354c478ac9433d2417d748 (patch) | |
tree | c837525029c9657ccf6edbc41e52952bab6f5f60 /Functions/FirebaseFunctions/FIRFunctions.m | |
parent | b271a6e25144be8cf872d028bb82336b5da2074c (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/FIRFunctions.m')
-rw-r--r-- | Functions/FirebaseFunctions/FIRFunctions.m | 19 |
1 files changed, 11 insertions, 8 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" ]; } |