Firebase function testes with local emulators, Firestore collection snapshot persists of claiming being emtpy

Viewed 36

Trying to test "locally" a firebase function with firebase emulators:start --inspect-functions on http:// 127 .0.0.1:5000. When debugging it step by step, the snapshot doesn't exist...but it's not. What I can possibly do wrong ?

const BotDetector = require("device-detector-js/dist/parsers/bot");
const fs = require("fs");
const DEBUG_BOT = true;

const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
const db = admin.firestore();


// Main firebase function called on firebase.json rewrites rules
exports.dynamicMetaTagsUpdate = functions.https.onRequest(async (request, response) => {

    let html = fs.readFileSync("../web/index.html", "utf8");
    const botDetector = new BotDetector();
    const userAgent = request.headers["user-agent"].toString();
    const bot = botDetector.parse(userAgent);

    if (bot || DEBUG_BOT) {
        try {
            const { postID } = request.query;
            const postUrl = 'http://localhost:5000/blog/post?postID=' + postID;

            const docRef = db.collection("posts").doc(postID);

            const postData = docRef.get().then((snapshot) => {

                if (snapshot.exists()) {

                    const object = {
                        postUrl: postUrl,```
0 Answers
Related