(FRONT) FRONT (2022)

<< Back << Firebase triggers.



1.Publish simple http handler to firebase functions.

2. Install Express packages and create REST API handler.

Init.ts contains opened DB with InitilazeApp by FirebaseAdmin and export Firebase.Srorage, other modules import DB

Db.Collection export Promise result, therefore we may use Than()

Instead Than() we can use Await wit Promise result.

We will use ForEach with Awaited result. We will define empty array and Callback inside ForEach will Push item to array.

Response need to resurn status code and result of REST API.

We can pass for Return JSON array as object {}.

In the same way Express allow as create Post, Delete and other type of REST API.

And now we can create Firebase Library function

But this is not all, next step is adding CORS library.

We need add Require(CORS) additionally to Require(Express) and Import DB and Firebase-Functions

Initialize CORS with the same domain origin true/false

Adn deploy Firebase ONLY function.

Firebase configure additional pre deployed step LINT, but this step not workable, we need simple delete this step from deployment config.

We can see deployed REST API in Firebase console.

3. Create Database Trigger. Transaction and binding to Transaction context will be Async.

Trigger need to use Database transaction. Transaction can be delete or update.

This triggers will be OnCreate and bind to Lessons documents.

We need to reference from Lesson to Course document therefore we use parent.parent to receive CourceID.

Inside transaction we can receive reference do document data.

We prepare object to collect number of lessons.

And update Course inside transaction.

Firebase function need to return task, transaction alway return what we need for OnCreate trigger.

Deploy this function and see result.






Comments ( )
<00>  <01>  <02>  <03>  <04>  <05>  <06>  <07>  <08>  <09>  <10>  <11>  <12>  <13>  <14>  <15>  <16>  <17>  <18>  <19>  <20>  <21>  <22>  <23
Link to this page: http://www.vb-net.com/FirebaseLearning/Rest.htm
<SITEMAP>  <MVC>  <ASP>  <NET>  <DATA>  <KIOSK>  <FLEX>  <SQL>  <NOTES>  <LINUX>  <MONO>  <FREEWARE>  <DOCS>  <ENG>  <CHAT ME>  <ABOUT ME>  < THANKS ME>