Skip to content

Commit 381eae5

Browse files
authored
feat(functions): support custom domains BREAKING requires firebase-ios-sdk 7.1.0+ / firebase-android-sdk 26.2.0+ (#4950)
* feat(functions) added custom domains * Updated test case for functions custom url * prefers emulator to custom domain testing * removed obsolete import Co-authored-by: Mike Diarmid <[email protected]> BREAKING CHANGE: minimum native SDK requirements now firebase-ios-sdk 7.1.0+ / firebase-android-sdk 26.2.0+
1 parent f501fff commit 381eae5

File tree

4 files changed

+48
-13
lines changed

4 files changed

+48
-13
lines changed

packages/functions/__tests__/functions.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ describe('Cloud Functions', function () {
2121
// @ts-ignore
2222
expect(functions()._useFunctionsEmulatorOrigin).toBe('http://10.0.2.2');
2323
});
24+
25+
it('prefers emulator to custom domain', function () {
26+
const app = firebase.app();
27+
const customUrl = 'https://test.com';
28+
const functions = app.functions(customUrl);
29+
30+
functions.useFunctionsEmulator('http://10.0.2.2');
31+
32+
// @ts-ignore
33+
expect(functions._useFunctionsEmulatorOrigin).toBe('http://10.0.2.2');
34+
});
2435
});
2536

2637
describe('httpcallable()', function () {

packages/functions/e2e/functions.e2e.js

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,37 @@ describe('functions()', function () {
5151
const response = await functionRunner();
5252
response.data.should.equal(region);
5353
});
54-
});
5554

56-
it('useFunctionsEmulator', async function () {
57-
const region = 'europe-west2';
58-
const fnName = 'invertaseReactNativeFirebaseFunctionsEmulator';
59-
const functions = firebase.app().functions(region);
55+
it('accepts passing in a custom url string as first arg to an app', async function () {
56+
const customUrl = 'https://us-central1-react-native-firebase-testing.cloudfunctions.net';
57+
const functionsForCustomUrl = firebase.app().functions(customUrl);
58+
59+
functionsForCustomUrl._customUrlOrRegion.should.equal(customUrl);
60+
functionsForCustomUrl.app.should.equal(firebase.app());
61+
functionsForCustomUrl.app.name.should.equal(firebase.app().name);
62+
63+
functionsForCustomUrl.app.should.equal(firebase.app());
64+
65+
functionsForCustomUrl._customUrlOrRegion.should.equal(customUrl);
6066

61-
functions.useFunctionsEmulator('http://api.rnfirebase.io');
67+
const functionRunner = functionsForCustomUrl.httpsCallable('testFunctionDefaultRegion');
6268

63-
const response = await functions.httpsCallable(fnName)();
69+
const response = await functionRunner();
70+
response.data.should.equal('null');
71+
});
6472

65-
response.data.region.should.equal(region);
66-
response.data.fnName.should.equal(fnName);
73+
it('useFunctionsEmulator', async function () {
74+
const region = 'europe-west2';
75+
const fnName = 'invertaseReactNativeFirebaseFunctionsEmulator';
76+
const functions = firebase.app().functions(region);
77+
78+
functions.useFunctionsEmulator('http://api.rnfirebase.io');
79+
80+
const response = await functions.httpsCallable(fnName)();
81+
82+
response.data.region.should.equal(region);
83+
response.data.fnName.should.equal(fnName);
84+
});
6785
});
6886

6987
describe('httpsCallable(fnName)(args)', function () {

packages/functions/ios/RNFBFunctions/RNFBFunctionsModule.m

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ @implementation RNFBFunctionsModule
3333

3434
RCT_EXPORT_METHOD(httpsCallable:
3535
(FIRApp *) firebaseApp
36-
region:
37-
(NSString *) region
36+
customUrlOrRegion:
37+
(NSString *) customUrlOrRegion
3838
origin:
3939
(NSString *) origin
4040
name:
@@ -48,7 +48,13 @@ @implementation RNFBFunctionsModule
4848
rejecter:
4949
(RCTPromiseRejectBlock) reject
5050
) {
51-
FIRFunctions *functions = [FIRFunctions functionsForApp:firebaseApp region:region];
51+
52+
NSURL *url = [NSURL URLWithString:customUrlOrRegion];
53+
FIRFunctions *functions = (url && url.scheme && url.host) ? [FIRFunctions functionsForApp:firebaseApp customDomain:customUrlOrRegion] : [FIRFunctions functionsForApp:firebaseApp region:customUrlOrRegion];
54+
55+
56+
57+
5258

5359
if (origin != nil) {
5460
[functions useFunctionsEmulatorOrigin:origin];

packages/functions/lib/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ declare module '@react-native-firebase/app' {
390390
>;
391391
}
392392
interface FirebaseApp {
393-
functions(region?: string): FirebaseFunctionsTypes.Module;
393+
functions(customUrlOrRegion?: string): FirebaseFunctionsTypes.Module;
394394
}
395395
}
396396
}

0 commit comments

Comments
 (0)