Hesam
Hesam

Reputation: 53610

Why Local Firestore Emulator doesn't react to the trigger?

I have this block of code in my /functions/src/index.ts:

export const onAddReviewerSendEmailNotification = functions
    .runWith({
      timeoutSeconds: 15,
    })
    .firestore.document("records/{email}/managedByOthers/{reviewerEmail}")
    .onWrite( (snap, context) => {
      functions.logger.info("something changed!");
      functions.logger.debug(`Running add reviewer trigger for userId: ${context.params.email}, reviewerId: ${context.params.reviewerEmail}`);
    });

I compile it using npm run build in the functions directory. Then I run the emulator using this command:

firebase emulators:start --only firestore,storage,functions --import test-data

This is what I get: enter image description here

I can see emulator UI is running. I go to firestore and add a record in this path: records/{email}/managedByOthers/{reviewerEmail}. Then I go to emulator's Logs section. Nothing has been logged. Am I doing something wrong?

Upvotes: 1

Views: 291

Answers (1)

Hesam
Hesam

Reputation: 53610

I finally found the solution after wasting 4 hours on the issue. I replaced

"functions": {
      "port": 5001
    },

by

"functions": {
      "host": "0.0.0.0",
      "port": 5001
    },

in the firebase.json file. I am able to see the logs now!

Upvotes: 1

Related Questions