Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(functions): support custom domains #4950

Merged
merged 12 commits into from
Mar 3, 2021
18 changes: 18 additions & 0 deletions packages/functions/e2e/functions.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ describe('functions()', function () {
const response = await functionRunner();
response.data.should.equal(region);
});

it('accepts passing in a custom url string as first arg to an app', async function () {
mikehardy marked this conversation as resolved.
Show resolved Hide resolved
const customUrl = 'https://us-central1-react-native-firebase-testing.cloudfunctions.net';
const functionsForRegion = firebase.app().functions(customUrl);
dackers86 marked this conversation as resolved.
Show resolved Hide resolved

functionsForRegion._customUrlOrRegion.should.equal(customUrl);
functionsForRegion.app.should.equal(firebase.app());
functionsForRegion.app.name.should.equal(firebase.app().name);

firebase.app().functions(customUrl).app.should.equal(firebase.app());
dackers86 marked this conversation as resolved.
Show resolved Hide resolved

firebase.app().functions(customUrl)._customUrlOrRegion.should.equal(customUrl);

const functionRunner = functionsForRegion.httpsCallable('testFunctionDefaultRegion');

const response = await functionRunner();
response.data.should.equal('null');
});
});

it('useFunctionsEmulator', async function () {
Expand Down
12 changes: 9 additions & 3 deletions packages/functions/ios/RNFBFunctions/RNFBFunctionsModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ @implementation RNFBFunctionsModule

RCT_EXPORT_METHOD(httpsCallable:
(FIRApp *) firebaseApp
region:
(NSString *) region
customUrlOrRegion:
(NSString *) customUrlOrRegion
origin:
(NSString *) origin
name:
Expand All @@ -48,7 +48,13 @@ @implementation RNFBFunctionsModule
rejecter:
(RCTPromiseRejectBlock) reject
) {
FIRFunctions *functions = [FIRFunctions functionsForApp:firebaseApp region:region];

NSURL *url = [NSURL URLWithString:customUrlOrRegion];
FIRFunctions *functions = (url && url.scheme && url.host) ? [FIRFunctions functionsForApp:firebaseApp customDomain:customUrlOrRegion] : [FIRFunctions functionsForApp:firebaseApp region:customUrlOrRegion];





if (origin != nil) {
[functions useFunctionsEmulatorOrigin:origin];
Expand Down
2 changes: 1 addition & 1 deletion packages/functions/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ declare module '@react-native-firebase/app' {
>;
}
interface FirebaseApp {
functions(region?: string): FirebaseFunctionsTypes.Module;
functions(customUrlOrRegion?: string): FirebaseFunctionsTypes.Module;
}
}
}