Skip to content

fix(functions): Set default functions region and add documentation - fix #1945 #1946

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

Merged
merged 2 commits into from
Nov 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/functions/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,29 @@ import { environment } from '../environments/environment';
export class AppModule {}
```

### Configure the Function region with the FunctionsRegionToken Injection Token

Allow configuration of Function region with the `FunctionsRegionToken` Injection Token by adding it to the `providers` section of your `NgModule`. The default is `us-central1`.

```ts
import { NgModule } from '@angular/core';
import { AngularFireFunctionsModule, FunctionsRegionToken } from '@angular/fire/functions';

@NgModule({
imports: [
...
AngularFireFunctionsModule,
...
],
...
providers: [
{ provide: FunctionsRegionToken, useValue: 'asia-northeast1' }
]
})
export class AppModule {}

```

### Injecting the AngularFireFunctions service

Once the `AngularFireFunctionsModule` is registered you can inject the `AngularFireFunctions` service.
Expand Down
3 changes: 2 additions & 1 deletion src/functions/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { FirebaseOptions, FirebaseAppConfig } from '@angular/fire';
import { FirebaseFunctions, FirebaseOptionsToken, FirebaseNameOrConfigToken, _firebaseAppFactory, FirebaseZoneScheduler } from '@angular/fire';

export const FunctionsRegionToken = new InjectionToken<string>('angularfire2.functions.region');
export const FunctionsDefaultRegion = 'us-central1';

@Injectable()
export class AngularFireFunctions {
Expand All @@ -27,7 +28,7 @@ export class AngularFireFunctions {

this.functions = zone.runOutsideAngular(() => {
const app = _firebaseAppFactory(options, nameOrConfig);
return app.functions(region);
return app.functions(region || FunctionsDefaultRegion);
});

}
Expand Down