vendredi 24 novembre 2017

Why invoking firebase cloud function on local simulator doesn't return any output?

I wanted to invoke (or test) my cloud functions before deploying. I found this reference http://ift.tt/2iOr4Cu.

I am using the shell to invoke and pass the test data for my function, but i always get the response as Successfully invoked function. I have few output statement inside my function using console.log(), but that never gets printed.

firebase > post_deleted({"brand" : "Gucci","category" : "FULL LOOKS","postNumImages" : 1,"posterId" : "HcK5eIKU6jUlqhcg7t10OThZ2mq2","posterName" : "Steve Nash","reverseTimestamp" : -1.511338246002482E9,"salePrice" : 5,"size" : "medium","state" : "OPEN","subCategory" : "CASUAL","timestamp" : 1511338246036},{params:{postId:'-KzXlrvMtQ4PnDMiojz8'}})
'Successfully invoked function.'

firebase >

firebase >

My function code (partial)

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
console.log("before");
var gcloud_storage = require('@google-cloud/storage')({keyFilename: 
`${functions.config().serviceaccount.filename}`});
exports.post_deleted = functions.database.ref('/posts/{postId}').onDelete((event) => {
console.log("inside");
let postId = event.params.postId;
let snapshot = event.data.previous;
let subCategory = snapshot.child('subCategory').val();
let db = admin.database();
let tasksArray = [];

I deployed the function, its working as expected. Sorry, if i am missing something very obvious. Looking for advice. Thanks.

Aucun commentaire:

Enregistrer un commentaire