You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Firebase Cloud Functions let you automatically run backend code in response to events triggered by Firebase features and HTTPS requests. Your code is stored in Google's cloud and runs in a managed environment. There's no need to manage and scale your own servers.
- To set up and initialize Firebase for your NativeScript app, follow the instructions on the documentation of the [@nativescript/firebase-core](../firebase-core/) plugin.
30
+
31
+
<!-- ## Create your Firestore database
12
32
13
-
After you write and deploy a function, Google's servers begin to manage the function immediately. You can fire the function directly with an HTTP request, via the Cloud Functions module, or in the case of background functions, Google's servers will listen for events and run the function when it is triggered.
33
+
To create your Firestore database, follow the instructions at [Create a Cloud Firestore database](https://firebase.google.com/docs/firestore/quickstart#create). -->
14
34
15
-
For more information on use cases, view the [Firebase Cloud Functions](https://firebase.google.com/docs/functions/use-cases) documentation.
35
+
## Add the Firebase Functions SDK to your app
36
+
37
+
To add the Cloud Firebase Functions SDK to your app, install the `@nativescript/firebase-functions` plugin by running the following command in the root directory of your project.
38
+
39
+
```cli
40
+
npm install @nativescript/firebase-functions
41
+
```
16
42
17
-
## Usage
43
+
## Use @nativescript/firebase-functions
18
44
19
-
The Cloud Functions module provides the functionality to directly trigger deployed HTTPS callable functions, without worrying about security or implementing a HTTP request library.
45
+
The Cloud Functions module provides the functionality to directly trigger deployed HTTPS callable functions, without worrying about security or implementing an HTTP request library.
20
46
21
-
Functions deployed to Firebase have unique names, allowing you to easily identify which endpoint you wish to send a request to. To learn more about deploying Functions to Firebase, view the Writing & Deploying Functions documentation.
47
+
Functions deployed to Firebase have unique names, allowing you to easily identify which endpoint you wish to send a request to.
22
48
23
49
## Calling an endpoint
24
50
25
-
Assuming we have a deployed a callable endpoint named listProducts, to call the endpoint the library exposes a httpsCallable method. For example:
51
+
Assuming we have to deploy a callable endpoint named `listProducts`. To call the endpoint, the library exposes a `httpsCallable` method. For example:
## Set and access regional Cloud Functions endpoints
78
+
52
79
Cloud Functions are _regional_, which means the infrastructure that runs your Cloud Function is located in specific regions.
53
80
54
-
By default, functions run in the _us-central1_ region. View the [supported regions](https://firebase.google.com/docs/functions/locations).
81
+
By default, functions run in the `us-central1` region. To see supported regions, see [supported regions](https://firebase.google.com/docs/functions/locations#supported_regions).
82
+
83
+
### Set regional function endpoint
55
84
56
-
To run functions in a different region, after initializing Firebase App set the region using _firebase().app().functions(region)_.
85
+
To run functions in a different region after initializing Firebase App, set the region using `firebase().app().functions(region)`.
57
86
58
-
Regional function endpoint example (using _europe-west2_ region ):
87
+
The code below shows an example of setting a regional function endpoint(`europe-west2`):
Whilst developing your application with Cloud Functions, it is possible to run the functions inside of a local emulator.
119
+
Whilst developing your application with Cloud Functions, you can run the functions inside of a local emulator.
89
120
90
-
To call the emulated functions, call the useEmulator method exposed by the library:
121
+
To call the emulated functions, connect the Cloud Functions to a local emulator by calling the [useEmulator](#useemulator) method on the `Functions` instance with the host and port of the emulator.
Returns a task function that can be called with optional data. The task function returns a Promise that will be resolved with the result(`HttpsCallableResult`) of the function execution. If the task fails, the Promise will be rejected with an [HttpsCallableError](https://github.com/NativeScript/firebase/blob/main/packages/firebase-functions/index.d.ts#L6-L10).
177
+
178
+
| Parameter | Type | Description |
179
+
| --- | --- | --- |
180
+
|`name`|`string`| The name of the reference to the Callable HTTPS trigger. |
181
+
|`options`|[HttpsCallableOptions](https://github.com/NativeScript/firebase/blob/main/packages/firebase-functions/common.ts#L5-L7)| An _optional_ object that sets the length of timeout, in `seconds`, for calls for this `Functions` instance. |
182
+
183
+
---
184
+
185
+
#### useEmulator()
186
+
```ts
187
+
firebase().functions().useEmulator(host, port);
188
+
```
189
+
Allows you to test Cloud Functions locally by connecting to the emulator.
190
+
191
+
| Parameter | Type | Description |
192
+
| --- | --- | --- |
193
+
|`host`|`string`| The host of the emulator to connect to. |
194
+
|`port`|`number`| The port of the emulator to connect to. |
0 commit comments